
Use [SPL]
Go
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.Status_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.Status_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.Status_Get_List
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: KVT (kvt.dyndns.org)
-- Purpose: Gets all records from the Status table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.Status_Get_List

AS


				
				SELECT
					[Id],
					[Name],
					[Value]
				FROM
					[dbo].[Status]
					
				Select @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.Status_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.Status_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.Status_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: KVT (kvt.dyndns.org)
-- Purpose: Gets records from the Status table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.Status_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[Id]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [Id]'
				SET @SQL = @SQL + ', [Name]'
				SET @SQL = @SQL + ', [Value]'
				SET @SQL = @SQL + ' FROM [dbo].[Status]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [Id],'
				SET @SQL = @SQL + ' [Name],'
				SET @SQL = @SQL + ' [Value]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				exec sp_executesql @SQL
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [dbo].[Status]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.Status_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.Status_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.Status_Insert
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: KVT (kvt.dyndns.org)
-- Purpose: Inserts a record into the Status table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.Status_Insert
(

	@Id int   ,

	@Name nvarchar (50)  ,

	@Value int   
)
AS


					
				INSERT INTO [dbo].[Status]
					(
					[Id]
					,[Name]
					,[Value]
					)
				VALUES
					(
					@Id
					,@Name
					,@Value
					)
				
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.Status_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.Status_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.Status_Update
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: KVT (kvt.dyndns.org)
-- Purpose: Updates a record in the Status table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.Status_Update
(

	@Id int   ,

	@OriginalId int   ,

	@Name nvarchar (50)  ,

	@Value int   
)
AS


				
				
				-- Modify the updatable columns
				UPDATE
					[dbo].[Status]
				SET
					[Id] = @Id
					,[Name] = @Name
					,[Value] = @Value
				WHERE
[Id] = @OriginalId 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.Status_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.Status_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.Status_Delete
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: KVT (kvt.dyndns.org)
-- Purpose: Deletes a record in the Status table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.Status_Delete
(

	@Id int   
)
AS


				DELETE FROM [dbo].[Status] WITH (ROWLOCK) 
				WHERE
					[Id] = @Id
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.Status_GetById procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.Status_GetById') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.Status_GetById
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: KVT (kvt.dyndns.org)
-- Purpose: Select records from the Status table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.Status_GetById
(

	@Id int   
)
AS


				SELECT
					[Id],
					[Name],
					[Value]
				FROM
					[dbo].[Status]
				WHERE
					[Id] = @Id
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.Status_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.Status_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.Status_Find
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: KVT (kvt.dyndns.org)
-- Purpose: Finds records in the Status table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.Status_Find
(

	@SearchUsingOR bit   = null ,

	@Id int   = null ,

	@Name nvarchar (50)  = null ,

	@Value int   = null 
)
AS


				
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [Id]
	, [Name]
	, [Value]
    FROM
	[dbo].[Status]
    WHERE 
	 ([Id] = @Id OR @Id is null)
	AND ([Name] = @Name OR @Name is null)
	AND ([Value] = @Value OR @Value is null)
						
  END
  ELSE
  BEGIN
    SELECT
	  [Id]
	, [Name]
	, [Value]
    FROM
	[dbo].[Status]
    WHERE 
	 ([Id] = @Id AND @Id is not null)
	OR ([Name] = @Name AND @Name is not null)
	OR ([Value] = @Value AND @Value is not null)
	Select @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.Department_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.Department_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.Department_Get_List
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: KVT (kvt.dyndns.org)
-- Purpose: Gets all records from the Department table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.Department_Get_List

AS


				
				SELECT
					[Id],
					[Name],
					[Description],
					[Value]
				FROM
					[dbo].[Department]
					
				Select @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.Department_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.Department_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.Department_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: KVT (kvt.dyndns.org)
-- Purpose: Gets records from the Department table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.Department_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[Id]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [Id]'
				SET @SQL = @SQL + ', [Name]'
				SET @SQL = @SQL + ', [Description]'
				SET @SQL = @SQL + ', [Value]'
				SET @SQL = @SQL + ' FROM [dbo].[Department]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [Id],'
				SET @SQL = @SQL + ' [Name],'
				SET @SQL = @SQL + ' [Description],'
				SET @SQL = @SQL + ' [Value]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				exec sp_executesql @SQL
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [dbo].[Department]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.Department_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.Department_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.Department_Insert
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: KVT (kvt.dyndns.org)
-- Purpose: Inserts a record into the Department table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.Department_Insert
(

	@Id int    OUTPUT,

	@Name nvarchar (50)  ,

	@Description nvarchar (500)  ,

	@Value int   
)
AS


					
				INSERT INTO [dbo].[Department]
					(
					[Name]
					,[Description]
					,[Value]
					)
				VALUES
					(
					@Name
					,@Description
					,@Value
					)
				
				-- Get the identity value
				SET @Id = SCOPE_IDENTITY()
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.Department_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.Department_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.Department_Update
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: KVT (kvt.dyndns.org)
-- Purpose: Updates a record in the Department table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.Department_Update
(

	@Id int   ,

	@Name nvarchar (50)  ,

	@Description nvarchar (500)  ,

	@Value int   
)
AS


				
				
				-- Modify the updatable columns
				UPDATE
					[dbo].[Department]
				SET
					[Name] = @Name
					,[Description] = @Description
					,[Value] = @Value
				WHERE
[Id] = @Id 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.Department_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.Department_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.Department_Delete
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: KVT (kvt.dyndns.org)
-- Purpose: Deletes a record in the Department table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.Department_Delete
(

	@Id int   
)
AS


				DELETE FROM [dbo].[Department] WITH (ROWLOCK) 
				WHERE
					[Id] = @Id
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.Department_GetById procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.Department_GetById') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.Department_GetById
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: KVT (kvt.dyndns.org)
-- Purpose: Select records from the Department table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.Department_GetById
(

	@Id int   
)
AS


				SELECT
					[Id],
					[Name],
					[Description],
					[Value]
				FROM
					[dbo].[Department]
				WHERE
					[Id] = @Id
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.Department_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.Department_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.Department_Find
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: KVT (kvt.dyndns.org)
-- Purpose: Finds records in the Department table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.Department_Find
(

	@SearchUsingOR bit   = null ,

	@Id int   = null ,

	@Name nvarchar (50)  = null ,

	@Description nvarchar (500)  = null ,

	@Value int   = null 
)
AS


				
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [Id]
	, [Name]
	, [Description]
	, [Value]
    FROM
	[dbo].[Department]
    WHERE 
	 ([Id] = @Id OR @Id is null)
	AND ([Name] = @Name OR @Name is null)
	AND ([Description] = @Description OR @Description is null)
	AND ([Value] = @Value OR @Value is null)
						
  END
  ELSE
  BEGIN
    SELECT
	  [Id]
	, [Name]
	, [Description]
	, [Value]
    FROM
	[dbo].[Department]
    WHERE 
	 ([Id] = @Id AND @Id is not null)
	OR ([Name] = @Name AND @Name is not null)
	OR ([Description] = @Description AND @Description is not null)
	OR ([Value] = @Value AND @Value is not null)
	Select @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.Role_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.Role_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.Role_Get_List
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: KVT (kvt.dyndns.org)
-- Purpose: Gets all records from the Role table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.Role_Get_List

AS


				
				SELECT
					[Id],
					[Name],
					[Description],
					[Value]
				FROM
					[dbo].[Role]
					
				Select @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.Role_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.Role_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.Role_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: KVT (kvt.dyndns.org)
-- Purpose: Gets records from the Role table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.Role_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[Id]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [Id]'
				SET @SQL = @SQL + ', [Name]'
				SET @SQL = @SQL + ', [Description]'
				SET @SQL = @SQL + ', [Value]'
				SET @SQL = @SQL + ' FROM [dbo].[Role]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [Id],'
				SET @SQL = @SQL + ' [Name],'
				SET @SQL = @SQL + ' [Description],'
				SET @SQL = @SQL + ' [Value]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				exec sp_executesql @SQL
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [dbo].[Role]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.Role_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.Role_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.Role_Insert
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: KVT (kvt.dyndns.org)
-- Purpose: Inserts a record into the Role table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.Role_Insert
(

	@Id int    OUTPUT,

	@Name nvarchar (50)  ,

	@Description nvarchar (200)  ,

	@Value int   
)
AS


					
				INSERT INTO [dbo].[Role]
					(
					[Name]
					,[Description]
					,[Value]
					)
				VALUES
					(
					@Name
					,@Description
					,@Value
					)
				
				-- Get the identity value
				SET @Id = SCOPE_IDENTITY()
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.Role_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.Role_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.Role_Update
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: KVT (kvt.dyndns.org)
-- Purpose: Updates a record in the Role table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.Role_Update
(

	@Id int   ,

	@Name nvarchar (50)  ,

	@Description nvarchar (200)  ,

	@Value int   
)
AS


				
				
				-- Modify the updatable columns
				UPDATE
					[dbo].[Role]
				SET
					[Name] = @Name
					,[Description] = @Description
					,[Value] = @Value
				WHERE
[Id] = @Id 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.Role_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.Role_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.Role_Delete
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: KVT (kvt.dyndns.org)
-- Purpose: Deletes a record in the Role table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.Role_Delete
(

	@Id int   
)
AS


				DELETE FROM [dbo].[Role] WITH (ROWLOCK) 
				WHERE
					[Id] = @Id
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.Role_GetById procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.Role_GetById') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.Role_GetById
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: KVT (kvt.dyndns.org)
-- Purpose: Select records from the Role table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.Role_GetById
(

	@Id int   
)
AS


				SELECT
					[Id],
					[Name],
					[Description],
					[Value]
				FROM
					[dbo].[Role]
				WHERE
					[Id] = @Id
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.Role_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.Role_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.Role_Find
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: KVT (kvt.dyndns.org)
-- Purpose: Finds records in the Role table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.Role_Find
(

	@SearchUsingOR bit   = null ,

	@Id int   = null ,

	@Name nvarchar (50)  = null ,

	@Description nvarchar (200)  = null ,

	@Value int   = null 
)
AS


				
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [Id]
	, [Name]
	, [Description]
	, [Value]
    FROM
	[dbo].[Role]
    WHERE 
	 ([Id] = @Id OR @Id is null)
	AND ([Name] = @Name OR @Name is null)
	AND ([Description] = @Description OR @Description is null)
	AND ([Value] = @Value OR @Value is null)
						
  END
  ELSE
  BEGIN
    SELECT
	  [Id]
	, [Name]
	, [Description]
	, [Value]
    FROM
	[dbo].[Role]
    WHERE 
	 ([Id] = @Id AND @Id is not null)
	OR ([Name] = @Name AND @Name is not null)
	OR ([Description] = @Description AND @Description is not null)
	OR ([Value] = @Value AND @Value is not null)
	Select @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.User_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.User_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.User_Get_List
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: KVT (kvt.dyndns.org)
-- Purpose: Gets all records from the User table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.User_Get_List

AS


				
				SELECT
					[Id],
					[Username],
					[DeptId],
					[RoleId],
					[IsActive],
					[Password]
				FROM
					[dbo].[User]
					
				Select @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.User_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.User_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.User_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: KVT (kvt.dyndns.org)
-- Purpose: Gets records from the User table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.User_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[Id]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [Id]'
				SET @SQL = @SQL + ', [Username]'
				SET @SQL = @SQL + ', [DeptId]'
				SET @SQL = @SQL + ', [RoleId]'
				SET @SQL = @SQL + ', [IsActive]'
				SET @SQL = @SQL + ', [Password]'
				SET @SQL = @SQL + ' FROM [dbo].[User]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [Id],'
				SET @SQL = @SQL + ' [Username],'
				SET @SQL = @SQL + ' [DeptId],'
				SET @SQL = @SQL + ' [RoleId],'
				SET @SQL = @SQL + ' [IsActive],'
				SET @SQL = @SQL + ' [Password]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				exec sp_executesql @SQL
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [dbo].[User]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.User_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.User_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.User_Insert
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: KVT (kvt.dyndns.org)
-- Purpose: Inserts a record into the User table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.User_Insert
(

	@Id int    OUTPUT,

	@Username nvarchar (50)  ,

	@DeptId int   ,

	@RoleId int   ,

	@IsActive bit   ,

	@Password nvarchar (50)  
)
AS


					
				INSERT INTO [dbo].[User]
					(
					[Username]
					,[DeptId]
					,[RoleId]
					,[IsActive]
					,[Password]
					)
				VALUES
					(
					@Username
					,@DeptId
					,@RoleId
					,@IsActive
					,@Password
					)
				
				-- Get the identity value
				SET @Id = SCOPE_IDENTITY()
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.User_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.User_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.User_Update
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: KVT (kvt.dyndns.org)
-- Purpose: Updates a record in the User table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.User_Update
(

	@Id int   ,

	@Username nvarchar (50)  ,

	@DeptId int   ,

	@RoleId int   ,

	@IsActive bit   ,

	@Password nvarchar (50)  
)
AS


				
				
				-- Modify the updatable columns
				UPDATE
					[dbo].[User]
				SET
					[Username] = @Username
					,[DeptId] = @DeptId
					,[RoleId] = @RoleId
					,[IsActive] = @IsActive
					,[Password] = @Password
				WHERE
[Id] = @Id 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.User_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.User_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.User_Delete
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: KVT (kvt.dyndns.org)
-- Purpose: Deletes a record in the User table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.User_Delete
(

	@Id int   
)
AS


				DELETE FROM [dbo].[User] WITH (ROWLOCK) 
				WHERE
					[Id] = @Id
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.User_GetByRoleId procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.User_GetByRoleId') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.User_GetByRoleId
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: KVT (kvt.dyndns.org)
-- Purpose: Select records from the User table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.User_GetByRoleId
(

	@RoleId int   
)
AS


				SET ANSI_NULLS OFF
				
				SELECT
					[Id],
					[Username],
					[DeptId],
					[RoleId],
					[IsActive],
					[Password]
				FROM
					[dbo].[User]
				WHERE
					[RoleId] = @RoleId
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.User_GetByDeptId procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.User_GetByDeptId') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.User_GetByDeptId
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: KVT (kvt.dyndns.org)
-- Purpose: Select records from the User table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.User_GetByDeptId
(

	@DeptId int   
)
AS


				SET ANSI_NULLS OFF
				
				SELECT
					[Id],
					[Username],
					[DeptId],
					[RoleId],
					[IsActive],
					[Password]
				FROM
					[dbo].[User]
				WHERE
					[DeptId] = @DeptId
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.User_GetById procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.User_GetById') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.User_GetById
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: KVT (kvt.dyndns.org)
-- Purpose: Select records from the User table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.User_GetById
(

	@Id int   
)
AS


				SELECT
					[Id],
					[Username],
					[DeptId],
					[RoleId],
					[IsActive],
					[Password]
				FROM
					[dbo].[User]
				WHERE
					[Id] = @Id
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.User_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.User_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.User_Find
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: KVT (kvt.dyndns.org)
-- Purpose: Finds records in the User table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.User_Find
(

	@SearchUsingOR bit   = null ,

	@Id int   = null ,

	@Username nvarchar (50)  = null ,

	@DeptId int   = null ,

	@RoleId int   = null ,

	@IsActive bit   = null ,

	@Password nvarchar (50)  = null 
)
AS


				
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [Id]
	, [Username]
	, [DeptId]
	, [RoleId]
	, [IsActive]
	, [Password]
    FROM
	[dbo].[User]
    WHERE 
	 ([Id] = @Id OR @Id is null)
	AND ([Username] = @Username OR @Username is null)
	AND ([DeptId] = @DeptId OR @DeptId is null)
	AND ([RoleId] = @RoleId OR @RoleId is null)
	AND ([IsActive] = @IsActive OR @IsActive is null)
	AND ([Password] = @Password OR @Password is null)
						
  END
  ELSE
  BEGIN
    SELECT
	  [Id]
	, [Username]
	, [DeptId]
	, [RoleId]
	, [IsActive]
	, [Password]
    FROM
	[dbo].[User]
    WHERE 
	 ([Id] = @Id AND @Id is not null)
	OR ([Username] = @Username AND @Username is not null)
	OR ([DeptId] = @DeptId AND @DeptId is not null)
	OR ([RoleId] = @RoleId AND @RoleId is not null)
	OR ([IsActive] = @IsActive AND @IsActive is not null)
	OR ([Password] = @Password AND @Password is not null)
	Select @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.PhieuXuat_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.PhieuXuat_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.PhieuXuat_Get_List
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: KVT (kvt.dyndns.org)
-- Purpose: Gets all records from the PhieuXuat table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.PhieuXuat_Get_List

AS


				
				SELECT
					[Id],
					[InputTime],
					[CreatedAt],
					[CreatedBy],
					[Latest],
					[Quantity],
					[Type],
					[Code]
				FROM
					[dbo].[PhieuXuat]
					
				Select @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.PhieuXuat_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.PhieuXuat_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.PhieuXuat_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: KVT (kvt.dyndns.org)
-- Purpose: Gets records from the PhieuXuat table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.PhieuXuat_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[Id]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [Id]'
				SET @SQL = @SQL + ', [InputTime]'
				SET @SQL = @SQL + ', [CreatedAt]'
				SET @SQL = @SQL + ', [CreatedBy]'
				SET @SQL = @SQL + ', [Latest]'
				SET @SQL = @SQL + ', [Quantity]'
				SET @SQL = @SQL + ', [Type]'
				SET @SQL = @SQL + ', [Code]'
				SET @SQL = @SQL + ' FROM [dbo].[PhieuXuat]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [Id],'
				SET @SQL = @SQL + ' [InputTime],'
				SET @SQL = @SQL + ' [CreatedAt],'
				SET @SQL = @SQL + ' [CreatedBy],'
				SET @SQL = @SQL + ' [Latest],'
				SET @SQL = @SQL + ' [Quantity],'
				SET @SQL = @SQL + ' [Type],'
				SET @SQL = @SQL + ' [Code]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				exec sp_executesql @SQL
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [dbo].[PhieuXuat]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.PhieuXuat_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.PhieuXuat_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.PhieuXuat_Insert
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: KVT (kvt.dyndns.org)
-- Purpose: Inserts a record into the PhieuXuat table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.PhieuXuat_Insert
(

	@Id int    OUTPUT,

	@InputTime datetime   ,

	@CreatedAt datetime   ,

	@CreatedBy int   ,

	@Latest int   ,

	@Quantity float   ,

	@Type nvarchar (50)  ,

	@Code nvarchar (50)  
)
AS


					
				INSERT INTO [dbo].[PhieuXuat]
					(
					[InputTime]
					,[CreatedAt]
					,[CreatedBy]
					,[Latest]
					,[Quantity]
					,[Type]
					,[Code]
					)
				VALUES
					(
					@InputTime
					,@CreatedAt
					,@CreatedBy
					,@Latest
					,@Quantity
					,@Type
					,@Code
					)
				
				-- Get the identity value
				SET @Id = SCOPE_IDENTITY()
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.PhieuXuat_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.PhieuXuat_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.PhieuXuat_Update
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: KVT (kvt.dyndns.org)
-- Purpose: Updates a record in the PhieuXuat table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.PhieuXuat_Update
(

	@Id int   ,

	@InputTime datetime   ,

	@CreatedAt datetime   ,

	@CreatedBy int   ,

	@Latest int   ,

	@Quantity float   ,

	@Type nvarchar (50)  ,

	@Code nvarchar (50)  
)
AS


				
				
				-- Modify the updatable columns
				UPDATE
					[dbo].[PhieuXuat]
				SET
					[InputTime] = @InputTime
					,[CreatedAt] = @CreatedAt
					,[CreatedBy] = @CreatedBy
					,[Latest] = @Latest
					,[Quantity] = @Quantity
					,[Type] = @Type
					,[Code] = @Code
				WHERE
[Id] = @Id 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.PhieuXuat_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.PhieuXuat_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.PhieuXuat_Delete
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: KVT (kvt.dyndns.org)
-- Purpose: Deletes a record in the PhieuXuat table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.PhieuXuat_Delete
(

	@Id int   
)
AS


				DELETE FROM [dbo].[PhieuXuat] WITH (ROWLOCK) 
				WHERE
					[Id] = @Id
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.PhieuXuat_GetByLatest procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.PhieuXuat_GetByLatest') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.PhieuXuat_GetByLatest
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: KVT (kvt.dyndns.org)
-- Purpose: Select records from the PhieuXuat table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.PhieuXuat_GetByLatest
(

	@Latest int   
)
AS


				SET ANSI_NULLS OFF
				
				SELECT
					[Id],
					[InputTime],
					[CreatedAt],
					[CreatedBy],
					[Latest],
					[Quantity],
					[Type],
					[Code]
				FROM
					[dbo].[PhieuXuat]
				WHERE
					[Latest] = @Latest
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.PhieuXuat_GetByCreatedBy procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.PhieuXuat_GetByCreatedBy') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.PhieuXuat_GetByCreatedBy
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: KVT (kvt.dyndns.org)
-- Purpose: Select records from the PhieuXuat table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.PhieuXuat_GetByCreatedBy
(

	@CreatedBy int   
)
AS


				SET ANSI_NULLS OFF
				
				SELECT
					[Id],
					[InputTime],
					[CreatedAt],
					[CreatedBy],
					[Latest],
					[Quantity],
					[Type],
					[Code]
				FROM
					[dbo].[PhieuXuat]
				WHERE
					[CreatedBy] = @CreatedBy
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.PhieuXuat_GetById procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.PhieuXuat_GetById') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.PhieuXuat_GetById
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: KVT (kvt.dyndns.org)
-- Purpose: Select records from the PhieuXuat table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.PhieuXuat_GetById
(

	@Id int   
)
AS


				SELECT
					[Id],
					[InputTime],
					[CreatedAt],
					[CreatedBy],
					[Latest],
					[Quantity],
					[Type],
					[Code]
				FROM
					[dbo].[PhieuXuat]
				WHERE
					[Id] = @Id
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.PhieuXuat_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.PhieuXuat_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.PhieuXuat_Find
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: KVT (kvt.dyndns.org)
-- Purpose: Finds records in the PhieuXuat table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.PhieuXuat_Find
(

	@SearchUsingOR bit   = null ,

	@Id int   = null ,

	@InputTime datetime   = null ,

	@CreatedAt datetime   = null ,

	@CreatedBy int   = null ,

	@Latest int   = null ,

	@Quantity float   = null ,

	@Type nvarchar (50)  = null ,

	@Code nvarchar (50)  = null 
)
AS


				
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [Id]
	, [InputTime]
	, [CreatedAt]
	, [CreatedBy]
	, [Latest]
	, [Quantity]
	, [Type]
	, [Code]
    FROM
	[dbo].[PhieuXuat]
    WHERE 
	 ([Id] = @Id OR @Id is null)
	AND ([InputTime] = @InputTime OR @InputTime is null)
	AND ([CreatedAt] = @CreatedAt OR @CreatedAt is null)
	AND ([CreatedBy] = @CreatedBy OR @CreatedBy is null)
	AND ([Latest] = @Latest OR @Latest is null)
	AND ([Quantity] = @Quantity OR @Quantity is null)
	AND ([Type] = @Type OR @Type is null)
	AND ([Code] = @Code OR @Code is null)
						
  END
  ELSE
  BEGIN
    SELECT
	  [Id]
	, [InputTime]
	, [CreatedAt]
	, [CreatedBy]
	, [Latest]
	, [Quantity]
	, [Type]
	, [Code]
    FROM
	[dbo].[PhieuXuat]
    WHERE 
	 ([Id] = @Id AND @Id is not null)
	OR ([InputTime] = @InputTime AND @InputTime is not null)
	OR ([CreatedAt] = @CreatedAt AND @CreatedAt is not null)
	OR ([CreatedBy] = @CreatedBy AND @CreatedBy is not null)
	OR ([Latest] = @Latest AND @Latest is not null)
	OR ([Quantity] = @Quantity AND @Quantity is not null)
	OR ([Type] = @Type AND @Type is not null)
	OR ([Code] = @Code AND @Code is not null)
	Select @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.TVT_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.TVT_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.TVT_Get_List
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: KVT (kvt.dyndns.org)
-- Purpose: Gets all records from the TVT table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.TVT_Get_List

AS


				
				SELECT
					[Id],
					[I1InputDate],
					[I7CondBHLuongNhap],
					[I8CondBHTenMeNhap],
					[I9CondBHKhac],
					[I10CondBHD1013],
					[I11BuproFT1011Nhap],
					[I12BuproFT1012Nhap],
					[I13BuproXeBonNhap],
					[I14BuproKhac],
					[I15DLPG],
					[I16CondNCSZ7900],
					[I17CondNCSKhac],
					[I18CondNCSBatchNO],
					[I19D7900],
					[I20CondBHXuatTheoMeter],
					[I21CondBHXuatTheoTank],
					[I22CondBHXuatTheoGiamDinh],
					[I23CondBHXuatKhac],
					[I24BuproTheoMeter],
					[I25BuproTheoTank],
					[I27BuproXuatTheoGiamDinhTamTinh],
					[I28BuproXuatKhac],
					[I29CondNCSXuatTheoMeter],
					[I30CondNCSXuatTheoTank],
					[I31CondNCSXuatTheoGiamDinh],
					[I32CondNCSXuatKhac],
					[I33CondNCSLiftNO],
					[I34LPGXaDot],
					[I35CondXaDot],
					[I36CondBHKhoiLuongTon],
					[I37CondBHTonMucA],
					[I38CondBHTonMucB],
					[I39BuproTon],
					[I40CondNCSKhoiLuongTon],
					[I41CondNCSTonMucA],
					[I42CondNCSTonMucB],
					[I65GhiChuNCS],
					[I66GhiChuNhap],
					[I67GhiChuXuat],
					[I68GhiChuTon],
					[I69GhiChuKhac],
					[Status],
					[CreatedUser],
					[Hid],
					[CreatedDate]
				FROM
					[dbo].[TVT]
					
				Select @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.TVT_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.TVT_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.TVT_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: KVT (kvt.dyndns.org)
-- Purpose: Gets records from the TVT table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.TVT_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[Id]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [Id]'
				SET @SQL = @SQL + ', [I1InputDate]'
				SET @SQL = @SQL + ', [I7CondBHLuongNhap]'
				SET @SQL = @SQL + ', [I8CondBHTenMeNhap]'
				SET @SQL = @SQL + ', [I9CondBHKhac]'
				SET @SQL = @SQL + ', [I10CondBHD1013]'
				SET @SQL = @SQL + ', [I11BuproFT1011Nhap]'
				SET @SQL = @SQL + ', [I12BuproFT1012Nhap]'
				SET @SQL = @SQL + ', [I13BuproXeBonNhap]'
				SET @SQL = @SQL + ', [I14BuproKhac]'
				SET @SQL = @SQL + ', [I15DLPG]'
				SET @SQL = @SQL + ', [I16CondNCSZ7900]'
				SET @SQL = @SQL + ', [I17CondNCSKhac]'
				SET @SQL = @SQL + ', [I18CondNCSBatchNO]'
				SET @SQL = @SQL + ', [I19D7900]'
				SET @SQL = @SQL + ', [I20CondBHXuatTheoMeter]'
				SET @SQL = @SQL + ', [I21CondBHXuatTheoTank]'
				SET @SQL = @SQL + ', [I22CondBHXuatTheoGiamDinh]'
				SET @SQL = @SQL + ', [I23CondBHXuatKhac]'
				SET @SQL = @SQL + ', [I24BuproTheoMeter]'
				SET @SQL = @SQL + ', [I25BuproTheoTank]'
				SET @SQL = @SQL + ', [I27BuproXuatTheoGiamDinhTamTinh]'
				SET @SQL = @SQL + ', [I28BuproXuatKhac]'
				SET @SQL = @SQL + ', [I29CondNCSXuatTheoMeter]'
				SET @SQL = @SQL + ', [I30CondNCSXuatTheoTank]'
				SET @SQL = @SQL + ', [I31CondNCSXuatTheoGiamDinh]'
				SET @SQL = @SQL + ', [I32CondNCSXuatKhac]'
				SET @SQL = @SQL + ', [I33CondNCSLiftNO]'
				SET @SQL = @SQL + ', [I34LPGXaDot]'
				SET @SQL = @SQL + ', [I35CondXaDot]'
				SET @SQL = @SQL + ', [I36CondBHKhoiLuongTon]'
				SET @SQL = @SQL + ', [I37CondBHTonMucA]'
				SET @SQL = @SQL + ', [I38CondBHTonMucB]'
				SET @SQL = @SQL + ', [I39BuproTon]'
				SET @SQL = @SQL + ', [I40CondNCSKhoiLuongTon]'
				SET @SQL = @SQL + ', [I41CondNCSTonMucA]'
				SET @SQL = @SQL + ', [I42CondNCSTonMucB]'
				SET @SQL = @SQL + ', [I65GhiChuNCS]'
				SET @SQL = @SQL + ', [I66GhiChuNhap]'
				SET @SQL = @SQL + ', [I67GhiChuXuat]'
				SET @SQL = @SQL + ', [I68GhiChuTon]'
				SET @SQL = @SQL + ', [I69GhiChuKhac]'
				SET @SQL = @SQL + ', [Status]'
				SET @SQL = @SQL + ', [CreatedUser]'
				SET @SQL = @SQL + ', [Hid]'
				SET @SQL = @SQL + ', [CreatedDate]'
				SET @SQL = @SQL + ' FROM [dbo].[TVT]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [Id],'
				SET @SQL = @SQL + ' [I1InputDate],'
				SET @SQL = @SQL + ' [I7CondBHLuongNhap],'
				SET @SQL = @SQL + ' [I8CondBHTenMeNhap],'
				SET @SQL = @SQL + ' [I9CondBHKhac],'
				SET @SQL = @SQL + ' [I10CondBHD1013],'
				SET @SQL = @SQL + ' [I11BuproFT1011Nhap],'
				SET @SQL = @SQL + ' [I12BuproFT1012Nhap],'
				SET @SQL = @SQL + ' [I13BuproXeBonNhap],'
				SET @SQL = @SQL + ' [I14BuproKhac],'
				SET @SQL = @SQL + ' [I15DLPG],'
				SET @SQL = @SQL + ' [I16CondNCSZ7900],'
				SET @SQL = @SQL + ' [I17CondNCSKhac],'
				SET @SQL = @SQL + ' [I18CondNCSBatchNO],'
				SET @SQL = @SQL + ' [I19D7900],'
				SET @SQL = @SQL + ' [I20CondBHXuatTheoMeter],'
				SET @SQL = @SQL + ' [I21CondBHXuatTheoTank],'
				SET @SQL = @SQL + ' [I22CondBHXuatTheoGiamDinh],'
				SET @SQL = @SQL + ' [I23CondBHXuatKhac],'
				SET @SQL = @SQL + ' [I24BuproTheoMeter],'
				SET @SQL = @SQL + ' [I25BuproTheoTank],'
				SET @SQL = @SQL + ' [I27BuproXuatTheoGiamDinhTamTinh],'
				SET @SQL = @SQL + ' [I28BuproXuatKhac],'
				SET @SQL = @SQL + ' [I29CondNCSXuatTheoMeter],'
				SET @SQL = @SQL + ' [I30CondNCSXuatTheoTank],'
				SET @SQL = @SQL + ' [I31CondNCSXuatTheoGiamDinh],'
				SET @SQL = @SQL + ' [I32CondNCSXuatKhac],'
				SET @SQL = @SQL + ' [I33CondNCSLiftNO],'
				SET @SQL = @SQL + ' [I34LPGXaDot],'
				SET @SQL = @SQL + ' [I35CondXaDot],'
				SET @SQL = @SQL + ' [I36CondBHKhoiLuongTon],'
				SET @SQL = @SQL + ' [I37CondBHTonMucA],'
				SET @SQL = @SQL + ' [I38CondBHTonMucB],'
				SET @SQL = @SQL + ' [I39BuproTon],'
				SET @SQL = @SQL + ' [I40CondNCSKhoiLuongTon],'
				SET @SQL = @SQL + ' [I41CondNCSTonMucA],'
				SET @SQL = @SQL + ' [I42CondNCSTonMucB],'
				SET @SQL = @SQL + ' [I65GhiChuNCS],'
				SET @SQL = @SQL + ' [I66GhiChuNhap],'
				SET @SQL = @SQL + ' [I67GhiChuXuat],'
				SET @SQL = @SQL + ' [I68GhiChuTon],'
				SET @SQL = @SQL + ' [I69GhiChuKhac],'
				SET @SQL = @SQL + ' [Status],'
				SET @SQL = @SQL + ' [CreatedUser],'
				SET @SQL = @SQL + ' [Hid],'
				SET @SQL = @SQL + ' [CreatedDate]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				exec sp_executesql @SQL
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [dbo].[TVT]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.TVT_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.TVT_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.TVT_Insert
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: KVT (kvt.dyndns.org)
-- Purpose: Inserts a record into the TVT table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.TVT_Insert
(

	@Id bigint    OUTPUT,

	@I1InputDate datetime   ,

	@I7CondBhLuongNhap float   ,

	@I8CondBhTenMeNhap nvarchar (50)  ,

	@I9CondBhKhac float   ,

	@I10CondBhd1013 float   ,

	@I11BuproFt1011Nhap float   ,

	@I12BuproFt1012Nhap float   ,

	@I13BuproXeBonNhap float   ,

	@I14BuproKhac float   ,

	@I15Dlpg float   ,

	@I16CondNcsz7900 float   ,

	@I17CondNcsKhac float   ,

	@I18CondNcsBatchNo nvarchar (50)  ,

	@I19d7900 float   ,

	@I20CondBhXuatTheoMeter float   ,

	@I21CondBhXuatTheoTank float   ,

	@I22CondBhXuatTheoGiamDinh float   ,

	@I23CondBhXuatKhac float   ,

	@I24BuproTheoMeter float   ,

	@I25BuproTheoTank float   ,

	@I27BuproXuatTheoGiamDinhTamTinh float   ,

	@I28BuproXuatKhac float   ,

	@I29CondNcsXuatTheoMeter float   ,

	@I30CondNcsXuatTheoTank float   ,

	@I31CondNcsXuatTheoGiamDinh float   ,

	@I32CondNcsXuatKhac float   ,

	@I33CondNcsLiftNo nvarchar (50)  ,

	@I34LpgXaDot float   ,

	@I35CondXaDot float   ,

	@I36CondBhKhoiLuongTon float   ,

	@I37CondBhTonMuca float   ,

	@I38CondBhTonMucb float   ,

	@I39BuproTon float   ,

	@I40CondNcsKhoiLuongTon float   ,

	@I41CondNcsTonMuca float   ,

	@I42CondNcsTonMucb float   ,

	@I65GhiChuNcs nvarchar (500)  ,

	@I66GhiChuNhap nvarchar (500)  ,

	@I67GhiChuXuat nvarchar (500)  ,

	@I68GhiChuTon nvarchar (500)  ,

	@I69GhiChuKhac nvarchar (500)  ,

	@Status int   ,

	@CreatedUser int   ,

	@Hid bigint   ,

	@CreatedDate datetime   
)
AS


					
				INSERT INTO [dbo].[TVT]
					(
					[I1InputDate]
					,[I7CondBHLuongNhap]
					,[I8CondBHTenMeNhap]
					,[I9CondBHKhac]
					,[I10CondBHD1013]
					,[I11BuproFT1011Nhap]
					,[I12BuproFT1012Nhap]
					,[I13BuproXeBonNhap]
					,[I14BuproKhac]
					,[I15DLPG]
					,[I16CondNCSZ7900]
					,[I17CondNCSKhac]
					,[I18CondNCSBatchNO]
					,[I19D7900]
					,[I20CondBHXuatTheoMeter]
					,[I21CondBHXuatTheoTank]
					,[I22CondBHXuatTheoGiamDinh]
					,[I23CondBHXuatKhac]
					,[I24BuproTheoMeter]
					,[I25BuproTheoTank]
					,[I27BuproXuatTheoGiamDinhTamTinh]
					,[I28BuproXuatKhac]
					,[I29CondNCSXuatTheoMeter]
					,[I30CondNCSXuatTheoTank]
					,[I31CondNCSXuatTheoGiamDinh]
					,[I32CondNCSXuatKhac]
					,[I33CondNCSLiftNO]
					,[I34LPGXaDot]
					,[I35CondXaDot]
					,[I36CondBHKhoiLuongTon]
					,[I37CondBHTonMucA]
					,[I38CondBHTonMucB]
					,[I39BuproTon]
					,[I40CondNCSKhoiLuongTon]
					,[I41CondNCSTonMucA]
					,[I42CondNCSTonMucB]
					,[I65GhiChuNCS]
					,[I66GhiChuNhap]
					,[I67GhiChuXuat]
					,[I68GhiChuTon]
					,[I69GhiChuKhac]
					,[Status]
					,[CreatedUser]
					,[Hid]
					,[CreatedDate]
					)
				VALUES
					(
					@I1InputDate
					,@I7CondBhLuongNhap
					,@I8CondBhTenMeNhap
					,@I9CondBhKhac
					,@I10CondBhd1013
					,@I11BuproFt1011Nhap
					,@I12BuproFt1012Nhap
					,@I13BuproXeBonNhap
					,@I14BuproKhac
					,@I15Dlpg
					,@I16CondNcsz7900
					,@I17CondNcsKhac
					,@I18CondNcsBatchNo
					,@I19d7900
					,@I20CondBhXuatTheoMeter
					,@I21CondBhXuatTheoTank
					,@I22CondBhXuatTheoGiamDinh
					,@I23CondBhXuatKhac
					,@I24BuproTheoMeter
					,@I25BuproTheoTank
					,@I27BuproXuatTheoGiamDinhTamTinh
					,@I28BuproXuatKhac
					,@I29CondNcsXuatTheoMeter
					,@I30CondNcsXuatTheoTank
					,@I31CondNcsXuatTheoGiamDinh
					,@I32CondNcsXuatKhac
					,@I33CondNcsLiftNo
					,@I34LpgXaDot
					,@I35CondXaDot
					,@I36CondBhKhoiLuongTon
					,@I37CondBhTonMuca
					,@I38CondBhTonMucb
					,@I39BuproTon
					,@I40CondNcsKhoiLuongTon
					,@I41CondNcsTonMuca
					,@I42CondNcsTonMucb
					,@I65GhiChuNcs
					,@I66GhiChuNhap
					,@I67GhiChuXuat
					,@I68GhiChuTon
					,@I69GhiChuKhac
					,@Status
					,@CreatedUser
					,@Hid
					,@CreatedDate
					)
				
				-- Get the identity value
				SET @Id = SCOPE_IDENTITY()
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.TVT_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.TVT_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.TVT_Update
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: KVT (kvt.dyndns.org)
-- Purpose: Updates a record in the TVT table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.TVT_Update
(

	@Id bigint   ,

	@I1InputDate datetime   ,

	@I7CondBhLuongNhap float   ,

	@I8CondBhTenMeNhap nvarchar (50)  ,

	@I9CondBhKhac float   ,

	@I10CondBhd1013 float   ,

	@I11BuproFt1011Nhap float   ,

	@I12BuproFt1012Nhap float   ,

	@I13BuproXeBonNhap float   ,

	@I14BuproKhac float   ,

	@I15Dlpg float   ,

	@I16CondNcsz7900 float   ,

	@I17CondNcsKhac float   ,

	@I18CondNcsBatchNo nvarchar (50)  ,

	@I19d7900 float   ,

	@I20CondBhXuatTheoMeter float   ,

	@I21CondBhXuatTheoTank float   ,

	@I22CondBhXuatTheoGiamDinh float   ,

	@I23CondBhXuatKhac float   ,

	@I24BuproTheoMeter float   ,

	@I25BuproTheoTank float   ,

	@I27BuproXuatTheoGiamDinhTamTinh float   ,

	@I28BuproXuatKhac float   ,

	@I29CondNcsXuatTheoMeter float   ,

	@I30CondNcsXuatTheoTank float   ,

	@I31CondNcsXuatTheoGiamDinh float   ,

	@I32CondNcsXuatKhac float   ,

	@I33CondNcsLiftNo nvarchar (50)  ,

	@I34LpgXaDot float   ,

	@I35CondXaDot float   ,

	@I36CondBhKhoiLuongTon float   ,

	@I37CondBhTonMuca float   ,

	@I38CondBhTonMucb float   ,

	@I39BuproTon float   ,

	@I40CondNcsKhoiLuongTon float   ,

	@I41CondNcsTonMuca float   ,

	@I42CondNcsTonMucb float   ,

	@I65GhiChuNcs nvarchar (500)  ,

	@I66GhiChuNhap nvarchar (500)  ,

	@I67GhiChuXuat nvarchar (500)  ,

	@I68GhiChuTon nvarchar (500)  ,

	@I69GhiChuKhac nvarchar (500)  ,

	@Status int   ,

	@CreatedUser int   ,

	@Hid bigint   ,

	@CreatedDate datetime   
)
AS


				
				
				-- Modify the updatable columns
				UPDATE
					[dbo].[TVT]
				SET
					[I1InputDate] = @I1InputDate
					,[I7CondBHLuongNhap] = @I7CondBhLuongNhap
					,[I8CondBHTenMeNhap] = @I8CondBhTenMeNhap
					,[I9CondBHKhac] = @I9CondBhKhac
					,[I10CondBHD1013] = @I10CondBhd1013
					,[I11BuproFT1011Nhap] = @I11BuproFt1011Nhap
					,[I12BuproFT1012Nhap] = @I12BuproFt1012Nhap
					,[I13BuproXeBonNhap] = @I13BuproXeBonNhap
					,[I14BuproKhac] = @I14BuproKhac
					,[I15DLPG] = @I15Dlpg
					,[I16CondNCSZ7900] = @I16CondNcsz7900
					,[I17CondNCSKhac] = @I17CondNcsKhac
					,[I18CondNCSBatchNO] = @I18CondNcsBatchNo
					,[I19D7900] = @I19d7900
					,[I20CondBHXuatTheoMeter] = @I20CondBhXuatTheoMeter
					,[I21CondBHXuatTheoTank] = @I21CondBhXuatTheoTank
					,[I22CondBHXuatTheoGiamDinh] = @I22CondBhXuatTheoGiamDinh
					,[I23CondBHXuatKhac] = @I23CondBhXuatKhac
					,[I24BuproTheoMeter] = @I24BuproTheoMeter
					,[I25BuproTheoTank] = @I25BuproTheoTank
					,[I27BuproXuatTheoGiamDinhTamTinh] = @I27BuproXuatTheoGiamDinhTamTinh
					,[I28BuproXuatKhac] = @I28BuproXuatKhac
					,[I29CondNCSXuatTheoMeter] = @I29CondNcsXuatTheoMeter
					,[I30CondNCSXuatTheoTank] = @I30CondNcsXuatTheoTank
					,[I31CondNCSXuatTheoGiamDinh] = @I31CondNcsXuatTheoGiamDinh
					,[I32CondNCSXuatKhac] = @I32CondNcsXuatKhac
					,[I33CondNCSLiftNO] = @I33CondNcsLiftNo
					,[I34LPGXaDot] = @I34LpgXaDot
					,[I35CondXaDot] = @I35CondXaDot
					,[I36CondBHKhoiLuongTon] = @I36CondBhKhoiLuongTon
					,[I37CondBHTonMucA] = @I37CondBhTonMuca
					,[I38CondBHTonMucB] = @I38CondBhTonMucb
					,[I39BuproTon] = @I39BuproTon
					,[I40CondNCSKhoiLuongTon] = @I40CondNcsKhoiLuongTon
					,[I41CondNCSTonMucA] = @I41CondNcsTonMuca
					,[I42CondNCSTonMucB] = @I42CondNcsTonMucb
					,[I65GhiChuNCS] = @I65GhiChuNcs
					,[I66GhiChuNhap] = @I66GhiChuNhap
					,[I67GhiChuXuat] = @I67GhiChuXuat
					,[I68GhiChuTon] = @I68GhiChuTon
					,[I69GhiChuKhac] = @I69GhiChuKhac
					,[Status] = @Status
					,[CreatedUser] = @CreatedUser
					,[Hid] = @Hid
					,[CreatedDate] = @CreatedDate
				WHERE
[Id] = @Id 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.TVT_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.TVT_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.TVT_Delete
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: KVT (kvt.dyndns.org)
-- Purpose: Deletes a record in the TVT table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.TVT_Delete
(

	@Id bigint   
)
AS


				DELETE FROM [dbo].[TVT] WITH (ROWLOCK) 
				WHERE
					[Id] = @Id
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.TVT_GetByStatus procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.TVT_GetByStatus') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.TVT_GetByStatus
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: KVT (kvt.dyndns.org)
-- Purpose: Select records from the TVT table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.TVT_GetByStatus
(

	@Status int   
)
AS


				SET ANSI_NULLS OFF
				
				SELECT
					[Id],
					[I1InputDate],
					[I7CondBHLuongNhap],
					[I8CondBHTenMeNhap],
					[I9CondBHKhac],
					[I10CondBHD1013],
					[I11BuproFT1011Nhap],
					[I12BuproFT1012Nhap],
					[I13BuproXeBonNhap],
					[I14BuproKhac],
					[I15DLPG],
					[I16CondNCSZ7900],
					[I17CondNCSKhac],
					[I18CondNCSBatchNO],
					[I19D7900],
					[I20CondBHXuatTheoMeter],
					[I21CondBHXuatTheoTank],
					[I22CondBHXuatTheoGiamDinh],
					[I23CondBHXuatKhac],
					[I24BuproTheoMeter],
					[I25BuproTheoTank],
					[I27BuproXuatTheoGiamDinhTamTinh],
					[I28BuproXuatKhac],
					[I29CondNCSXuatTheoMeter],
					[I30CondNCSXuatTheoTank],
					[I31CondNCSXuatTheoGiamDinh],
					[I32CondNCSXuatKhac],
					[I33CondNCSLiftNO],
					[I34LPGXaDot],
					[I35CondXaDot],
					[I36CondBHKhoiLuongTon],
					[I37CondBHTonMucA],
					[I38CondBHTonMucB],
					[I39BuproTon],
					[I40CondNCSKhoiLuongTon],
					[I41CondNCSTonMucA],
					[I42CondNCSTonMucB],
					[I65GhiChuNCS],
					[I66GhiChuNhap],
					[I67GhiChuXuat],
					[I68GhiChuTon],
					[I69GhiChuKhac],
					[Status],
					[CreatedUser],
					[Hid],
					[CreatedDate]
				FROM
					[dbo].[TVT]
				WHERE
					[Status] = @Status
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.TVT_GetByCreatedUser procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.TVT_GetByCreatedUser') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.TVT_GetByCreatedUser
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: KVT (kvt.dyndns.org)
-- Purpose: Select records from the TVT table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.TVT_GetByCreatedUser
(

	@CreatedUser int   
)
AS


				SET ANSI_NULLS OFF
				
				SELECT
					[Id],
					[I1InputDate],
					[I7CondBHLuongNhap],
					[I8CondBHTenMeNhap],
					[I9CondBHKhac],
					[I10CondBHD1013],
					[I11BuproFT1011Nhap],
					[I12BuproFT1012Nhap],
					[I13BuproXeBonNhap],
					[I14BuproKhac],
					[I15DLPG],
					[I16CondNCSZ7900],
					[I17CondNCSKhac],
					[I18CondNCSBatchNO],
					[I19D7900],
					[I20CondBHXuatTheoMeter],
					[I21CondBHXuatTheoTank],
					[I22CondBHXuatTheoGiamDinh],
					[I23CondBHXuatKhac],
					[I24BuproTheoMeter],
					[I25BuproTheoTank],
					[I27BuproXuatTheoGiamDinhTamTinh],
					[I28BuproXuatKhac],
					[I29CondNCSXuatTheoMeter],
					[I30CondNCSXuatTheoTank],
					[I31CondNCSXuatTheoGiamDinh],
					[I32CondNCSXuatKhac],
					[I33CondNCSLiftNO],
					[I34LPGXaDot],
					[I35CondXaDot],
					[I36CondBHKhoiLuongTon],
					[I37CondBHTonMucA],
					[I38CondBHTonMucB],
					[I39BuproTon],
					[I40CondNCSKhoiLuongTon],
					[I41CondNCSTonMucA],
					[I42CondNCSTonMucB],
					[I65GhiChuNCS],
					[I66GhiChuNhap],
					[I67GhiChuXuat],
					[I68GhiChuTon],
					[I69GhiChuKhac],
					[Status],
					[CreatedUser],
					[Hid],
					[CreatedDate]
				FROM
					[dbo].[TVT]
				WHERE
					[CreatedUser] = @CreatedUser
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.TVT_GetByHid procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.TVT_GetByHid') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.TVT_GetByHid
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: KVT (kvt.dyndns.org)
-- Purpose: Select records from the TVT table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.TVT_GetByHid
(

	@Hid bigint   
)
AS


				SET ANSI_NULLS OFF
				
				SELECT
					[Id],
					[I1InputDate],
					[I7CondBHLuongNhap],
					[I8CondBHTenMeNhap],
					[I9CondBHKhac],
					[I10CondBHD1013],
					[I11BuproFT1011Nhap],
					[I12BuproFT1012Nhap],
					[I13BuproXeBonNhap],
					[I14BuproKhac],
					[I15DLPG],
					[I16CondNCSZ7900],
					[I17CondNCSKhac],
					[I18CondNCSBatchNO],
					[I19D7900],
					[I20CondBHXuatTheoMeter],
					[I21CondBHXuatTheoTank],
					[I22CondBHXuatTheoGiamDinh],
					[I23CondBHXuatKhac],
					[I24BuproTheoMeter],
					[I25BuproTheoTank],
					[I27BuproXuatTheoGiamDinhTamTinh],
					[I28BuproXuatKhac],
					[I29CondNCSXuatTheoMeter],
					[I30CondNCSXuatTheoTank],
					[I31CondNCSXuatTheoGiamDinh],
					[I32CondNCSXuatKhac],
					[I33CondNCSLiftNO],
					[I34LPGXaDot],
					[I35CondXaDot],
					[I36CondBHKhoiLuongTon],
					[I37CondBHTonMucA],
					[I38CondBHTonMucB],
					[I39BuproTon],
					[I40CondNCSKhoiLuongTon],
					[I41CondNCSTonMucA],
					[I42CondNCSTonMucB],
					[I65GhiChuNCS],
					[I66GhiChuNhap],
					[I67GhiChuXuat],
					[I68GhiChuTon],
					[I69GhiChuKhac],
					[Status],
					[CreatedUser],
					[Hid],
					[CreatedDate]
				FROM
					[dbo].[TVT]
				WHERE
					[Hid] = @Hid
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.TVT_GetById procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.TVT_GetById') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.TVT_GetById
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: KVT (kvt.dyndns.org)
-- Purpose: Select records from the TVT table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.TVT_GetById
(

	@Id bigint   
)
AS


				SELECT
					[Id],
					[I1InputDate],
					[I7CondBHLuongNhap],
					[I8CondBHTenMeNhap],
					[I9CondBHKhac],
					[I10CondBHD1013],
					[I11BuproFT1011Nhap],
					[I12BuproFT1012Nhap],
					[I13BuproXeBonNhap],
					[I14BuproKhac],
					[I15DLPG],
					[I16CondNCSZ7900],
					[I17CondNCSKhac],
					[I18CondNCSBatchNO],
					[I19D7900],
					[I20CondBHXuatTheoMeter],
					[I21CondBHXuatTheoTank],
					[I22CondBHXuatTheoGiamDinh],
					[I23CondBHXuatKhac],
					[I24BuproTheoMeter],
					[I25BuproTheoTank],
					[I27BuproXuatTheoGiamDinhTamTinh],
					[I28BuproXuatKhac],
					[I29CondNCSXuatTheoMeter],
					[I30CondNCSXuatTheoTank],
					[I31CondNCSXuatTheoGiamDinh],
					[I32CondNCSXuatKhac],
					[I33CondNCSLiftNO],
					[I34LPGXaDot],
					[I35CondXaDot],
					[I36CondBHKhoiLuongTon],
					[I37CondBHTonMucA],
					[I38CondBHTonMucB],
					[I39BuproTon],
					[I40CondNCSKhoiLuongTon],
					[I41CondNCSTonMucA],
					[I42CondNCSTonMucB],
					[I65GhiChuNCS],
					[I66GhiChuNhap],
					[I67GhiChuXuat],
					[I68GhiChuTon],
					[I69GhiChuKhac],
					[Status],
					[CreatedUser],
					[Hid],
					[CreatedDate]
				FROM
					[dbo].[TVT]
				WHERE
					[Id] = @Id
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.TVT_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.TVT_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.TVT_Find
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: KVT (kvt.dyndns.org)
-- Purpose: Finds records in the TVT table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.TVT_Find
(

	@SearchUsingOR bit   = null ,

	@Id bigint   = null ,

	@I1InputDate datetime   = null ,

	@I7CondBhLuongNhap float   = null ,

	@I8CondBhTenMeNhap nvarchar (50)  = null ,

	@I9CondBhKhac float   = null ,

	@I10CondBhd1013 float   = null ,

	@I11BuproFt1011Nhap float   = null ,

	@I12BuproFt1012Nhap float   = null ,

	@I13BuproXeBonNhap float   = null ,

	@I14BuproKhac float   = null ,

	@I15Dlpg float   = null ,

	@I16CondNcsz7900 float   = null ,

	@I17CondNcsKhac float   = null ,

	@I18CondNcsBatchNo nvarchar (50)  = null ,

	@I19d7900 float   = null ,

	@I20CondBhXuatTheoMeter float   = null ,

	@I21CondBhXuatTheoTank float   = null ,

	@I22CondBhXuatTheoGiamDinh float   = null ,

	@I23CondBhXuatKhac float   = null ,

	@I24BuproTheoMeter float   = null ,

	@I25BuproTheoTank float   = null ,

	@I27BuproXuatTheoGiamDinhTamTinh float   = null ,

	@I28BuproXuatKhac float   = null ,

	@I29CondNcsXuatTheoMeter float   = null ,

	@I30CondNcsXuatTheoTank float   = null ,

	@I31CondNcsXuatTheoGiamDinh float   = null ,

	@I32CondNcsXuatKhac float   = null ,

	@I33CondNcsLiftNo nvarchar (50)  = null ,

	@I34LpgXaDot float   = null ,

	@I35CondXaDot float   = null ,

	@I36CondBhKhoiLuongTon float   = null ,

	@I37CondBhTonMuca float   = null ,

	@I38CondBhTonMucb float   = null ,

	@I39BuproTon float   = null ,

	@I40CondNcsKhoiLuongTon float   = null ,

	@I41CondNcsTonMuca float   = null ,

	@I42CondNcsTonMucb float   = null ,

	@I65GhiChuNcs nvarchar (500)  = null ,

	@I66GhiChuNhap nvarchar (500)  = null ,

	@I67GhiChuXuat nvarchar (500)  = null ,

	@I68GhiChuTon nvarchar (500)  = null ,

	@I69GhiChuKhac nvarchar (500)  = null ,

	@Status int   = null ,

	@CreatedUser int   = null ,

	@Hid bigint   = null ,

	@CreatedDate datetime   = null 
)
AS


				
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [Id]
	, [I1InputDate]
	, [I7CondBHLuongNhap]
	, [I8CondBHTenMeNhap]
	, [I9CondBHKhac]
	, [I10CondBHD1013]
	, [I11BuproFT1011Nhap]
	, [I12BuproFT1012Nhap]
	, [I13BuproXeBonNhap]
	, [I14BuproKhac]
	, [I15DLPG]
	, [I16CondNCSZ7900]
	, [I17CondNCSKhac]
	, [I18CondNCSBatchNO]
	, [I19D7900]
	, [I20CondBHXuatTheoMeter]
	, [I21CondBHXuatTheoTank]
	, [I22CondBHXuatTheoGiamDinh]
	, [I23CondBHXuatKhac]
	, [I24BuproTheoMeter]
	, [I25BuproTheoTank]
	, [I27BuproXuatTheoGiamDinhTamTinh]
	, [I28BuproXuatKhac]
	, [I29CondNCSXuatTheoMeter]
	, [I30CondNCSXuatTheoTank]
	, [I31CondNCSXuatTheoGiamDinh]
	, [I32CondNCSXuatKhac]
	, [I33CondNCSLiftNO]
	, [I34LPGXaDot]
	, [I35CondXaDot]
	, [I36CondBHKhoiLuongTon]
	, [I37CondBHTonMucA]
	, [I38CondBHTonMucB]
	, [I39BuproTon]
	, [I40CondNCSKhoiLuongTon]
	, [I41CondNCSTonMucA]
	, [I42CondNCSTonMucB]
	, [I65GhiChuNCS]
	, [I66GhiChuNhap]
	, [I67GhiChuXuat]
	, [I68GhiChuTon]
	, [I69GhiChuKhac]
	, [Status]
	, [CreatedUser]
	, [Hid]
	, [CreatedDate]
    FROM
	[dbo].[TVT]
    WHERE 
	 ([Id] = @Id OR @Id is null)
	AND ([I1InputDate] = @I1InputDate OR @I1InputDate is null)
	AND ([I7CondBHLuongNhap] = @I7CondBhLuongNhap OR @I7CondBhLuongNhap is null)
	AND ([I8CondBHTenMeNhap] = @I8CondBhTenMeNhap OR @I8CondBhTenMeNhap is null)
	AND ([I9CondBHKhac] = @I9CondBhKhac OR @I9CondBhKhac is null)
	AND ([I10CondBHD1013] = @I10CondBhd1013 OR @I10CondBhd1013 is null)
	AND ([I11BuproFT1011Nhap] = @I11BuproFt1011Nhap OR @I11BuproFt1011Nhap is null)
	AND ([I12BuproFT1012Nhap] = @I12BuproFt1012Nhap OR @I12BuproFt1012Nhap is null)
	AND ([I13BuproXeBonNhap] = @I13BuproXeBonNhap OR @I13BuproXeBonNhap is null)
	AND ([I14BuproKhac] = @I14BuproKhac OR @I14BuproKhac is null)
	AND ([I15DLPG] = @I15Dlpg OR @I15Dlpg is null)
	AND ([I16CondNCSZ7900] = @I16CondNcsz7900 OR @I16CondNcsz7900 is null)
	AND ([I17CondNCSKhac] = @I17CondNcsKhac OR @I17CondNcsKhac is null)
	AND ([I18CondNCSBatchNO] = @I18CondNcsBatchNo OR @I18CondNcsBatchNo is null)
	AND ([I19D7900] = @I19d7900 OR @I19d7900 is null)
	AND ([I20CondBHXuatTheoMeter] = @I20CondBhXuatTheoMeter OR @I20CondBhXuatTheoMeter is null)
	AND ([I21CondBHXuatTheoTank] = @I21CondBhXuatTheoTank OR @I21CondBhXuatTheoTank is null)
	AND ([I22CondBHXuatTheoGiamDinh] = @I22CondBhXuatTheoGiamDinh OR @I22CondBhXuatTheoGiamDinh is null)
	AND ([I23CondBHXuatKhac] = @I23CondBhXuatKhac OR @I23CondBhXuatKhac is null)
	AND ([I24BuproTheoMeter] = @I24BuproTheoMeter OR @I24BuproTheoMeter is null)
	AND ([I25BuproTheoTank] = @I25BuproTheoTank OR @I25BuproTheoTank is null)
	AND ([I27BuproXuatTheoGiamDinhTamTinh] = @I27BuproXuatTheoGiamDinhTamTinh OR @I27BuproXuatTheoGiamDinhTamTinh is null)
	AND ([I28BuproXuatKhac] = @I28BuproXuatKhac OR @I28BuproXuatKhac is null)
	AND ([I29CondNCSXuatTheoMeter] = @I29CondNcsXuatTheoMeter OR @I29CondNcsXuatTheoMeter is null)
	AND ([I30CondNCSXuatTheoTank] = @I30CondNcsXuatTheoTank OR @I30CondNcsXuatTheoTank is null)
	AND ([I31CondNCSXuatTheoGiamDinh] = @I31CondNcsXuatTheoGiamDinh OR @I31CondNcsXuatTheoGiamDinh is null)
	AND ([I32CondNCSXuatKhac] = @I32CondNcsXuatKhac OR @I32CondNcsXuatKhac is null)
	AND ([I33CondNCSLiftNO] = @I33CondNcsLiftNo OR @I33CondNcsLiftNo is null)
	AND ([I34LPGXaDot] = @I34LpgXaDot OR @I34LpgXaDot is null)
	AND ([I35CondXaDot] = @I35CondXaDot OR @I35CondXaDot is null)
	AND ([I36CondBHKhoiLuongTon] = @I36CondBhKhoiLuongTon OR @I36CondBhKhoiLuongTon is null)
	AND ([I37CondBHTonMucA] = @I37CondBhTonMuca OR @I37CondBhTonMuca is null)
	AND ([I38CondBHTonMucB] = @I38CondBhTonMucb OR @I38CondBhTonMucb is null)
	AND ([I39BuproTon] = @I39BuproTon OR @I39BuproTon is null)
	AND ([I40CondNCSKhoiLuongTon] = @I40CondNcsKhoiLuongTon OR @I40CondNcsKhoiLuongTon is null)
	AND ([I41CondNCSTonMucA] = @I41CondNcsTonMuca OR @I41CondNcsTonMuca is null)
	AND ([I42CondNCSTonMucB] = @I42CondNcsTonMucb OR @I42CondNcsTonMucb is null)
	AND ([I65GhiChuNCS] = @I65GhiChuNcs OR @I65GhiChuNcs is null)
	AND ([I66GhiChuNhap] = @I66GhiChuNhap OR @I66GhiChuNhap is null)
	AND ([I67GhiChuXuat] = @I67GhiChuXuat OR @I67GhiChuXuat is null)
	AND ([I68GhiChuTon] = @I68GhiChuTon OR @I68GhiChuTon is null)
	AND ([I69GhiChuKhac] = @I69GhiChuKhac OR @I69GhiChuKhac is null)
	AND ([Status] = @Status OR @Status is null)
	AND ([CreatedUser] = @CreatedUser OR @CreatedUser is null)
	AND ([Hid] = @Hid OR @Hid is null)
	AND ([CreatedDate] = @CreatedDate OR @CreatedDate is null)
						
  END
  ELSE
  BEGIN
    SELECT
	  [Id]
	, [I1InputDate]
	, [I7CondBHLuongNhap]
	, [I8CondBHTenMeNhap]
	, [I9CondBHKhac]
	, [I10CondBHD1013]
	, [I11BuproFT1011Nhap]
	, [I12BuproFT1012Nhap]
	, [I13BuproXeBonNhap]
	, [I14BuproKhac]
	, [I15DLPG]
	, [I16CondNCSZ7900]
	, [I17CondNCSKhac]
	, [I18CondNCSBatchNO]
	, [I19D7900]
	, [I20CondBHXuatTheoMeter]
	, [I21CondBHXuatTheoTank]
	, [I22CondBHXuatTheoGiamDinh]
	, [I23CondBHXuatKhac]
	, [I24BuproTheoMeter]
	, [I25BuproTheoTank]
	, [I27BuproXuatTheoGiamDinhTamTinh]
	, [I28BuproXuatKhac]
	, [I29CondNCSXuatTheoMeter]
	, [I30CondNCSXuatTheoTank]
	, [I31CondNCSXuatTheoGiamDinh]
	, [I32CondNCSXuatKhac]
	, [I33CondNCSLiftNO]
	, [I34LPGXaDot]
	, [I35CondXaDot]
	, [I36CondBHKhoiLuongTon]
	, [I37CondBHTonMucA]
	, [I38CondBHTonMucB]
	, [I39BuproTon]
	, [I40CondNCSKhoiLuongTon]
	, [I41CondNCSTonMucA]
	, [I42CondNCSTonMucB]
	, [I65GhiChuNCS]
	, [I66GhiChuNhap]
	, [I67GhiChuXuat]
	, [I68GhiChuTon]
	, [I69GhiChuKhac]
	, [Status]
	, [CreatedUser]
	, [Hid]
	, [CreatedDate]
    FROM
	[dbo].[TVT]
    WHERE 
	 ([Id] = @Id AND @Id is not null)
	OR ([I1InputDate] = @I1InputDate AND @I1InputDate is not null)
	OR ([I7CondBHLuongNhap] = @I7CondBhLuongNhap AND @I7CondBhLuongNhap is not null)
	OR ([I8CondBHTenMeNhap] = @I8CondBhTenMeNhap AND @I8CondBhTenMeNhap is not null)
	OR ([I9CondBHKhac] = @I9CondBhKhac AND @I9CondBhKhac is not null)
	OR ([I10CondBHD1013] = @I10CondBhd1013 AND @I10CondBhd1013 is not null)
	OR ([I11BuproFT1011Nhap] = @I11BuproFt1011Nhap AND @I11BuproFt1011Nhap is not null)
	OR ([I12BuproFT1012Nhap] = @I12BuproFt1012Nhap AND @I12BuproFt1012Nhap is not null)
	OR ([I13BuproXeBonNhap] = @I13BuproXeBonNhap AND @I13BuproXeBonNhap is not null)
	OR ([I14BuproKhac] = @I14BuproKhac AND @I14BuproKhac is not null)
	OR ([I15DLPG] = @I15Dlpg AND @I15Dlpg is not null)
	OR ([I16CondNCSZ7900] = @I16CondNcsz7900 AND @I16CondNcsz7900 is not null)
	OR ([I17CondNCSKhac] = @I17CondNcsKhac AND @I17CondNcsKhac is not null)
	OR ([I18CondNCSBatchNO] = @I18CondNcsBatchNo AND @I18CondNcsBatchNo is not null)
	OR ([I19D7900] = @I19d7900 AND @I19d7900 is not null)
	OR ([I20CondBHXuatTheoMeter] = @I20CondBhXuatTheoMeter AND @I20CondBhXuatTheoMeter is not null)
	OR ([I21CondBHXuatTheoTank] = @I21CondBhXuatTheoTank AND @I21CondBhXuatTheoTank is not null)
	OR ([I22CondBHXuatTheoGiamDinh] = @I22CondBhXuatTheoGiamDinh AND @I22CondBhXuatTheoGiamDinh is not null)
	OR ([I23CondBHXuatKhac] = @I23CondBhXuatKhac AND @I23CondBhXuatKhac is not null)
	OR ([I24BuproTheoMeter] = @I24BuproTheoMeter AND @I24BuproTheoMeter is not null)
	OR ([I25BuproTheoTank] = @I25BuproTheoTank AND @I25BuproTheoTank is not null)
	OR ([I27BuproXuatTheoGiamDinhTamTinh] = @I27BuproXuatTheoGiamDinhTamTinh AND @I27BuproXuatTheoGiamDinhTamTinh is not null)
	OR ([I28BuproXuatKhac] = @I28BuproXuatKhac AND @I28BuproXuatKhac is not null)
	OR ([I29CondNCSXuatTheoMeter] = @I29CondNcsXuatTheoMeter AND @I29CondNcsXuatTheoMeter is not null)
	OR ([I30CondNCSXuatTheoTank] = @I30CondNcsXuatTheoTank AND @I30CondNcsXuatTheoTank is not null)
	OR ([I31CondNCSXuatTheoGiamDinh] = @I31CondNcsXuatTheoGiamDinh AND @I31CondNcsXuatTheoGiamDinh is not null)
	OR ([I32CondNCSXuatKhac] = @I32CondNcsXuatKhac AND @I32CondNcsXuatKhac is not null)
	OR ([I33CondNCSLiftNO] = @I33CondNcsLiftNo AND @I33CondNcsLiftNo is not null)
	OR ([I34LPGXaDot] = @I34LpgXaDot AND @I34LpgXaDot is not null)
	OR ([I35CondXaDot] = @I35CondXaDot AND @I35CondXaDot is not null)
	OR ([I36CondBHKhoiLuongTon] = @I36CondBhKhoiLuongTon AND @I36CondBhKhoiLuongTon is not null)
	OR ([I37CondBHTonMucA] = @I37CondBhTonMuca AND @I37CondBhTonMuca is not null)
	OR ([I38CondBHTonMucB] = @I38CondBhTonMucb AND @I38CondBhTonMucb is not null)
	OR ([I39BuproTon] = @I39BuproTon AND @I39BuproTon is not null)
	OR ([I40CondNCSKhoiLuongTon] = @I40CondNcsKhoiLuongTon AND @I40CondNcsKhoiLuongTon is not null)
	OR ([I41CondNCSTonMucA] = @I41CondNcsTonMuca AND @I41CondNcsTonMuca is not null)
	OR ([I42CondNCSTonMucB] = @I42CondNcsTonMucb AND @I42CondNcsTonMucb is not null)
	OR ([I65GhiChuNCS] = @I65GhiChuNcs AND @I65GhiChuNcs is not null)
	OR ([I66GhiChuNhap] = @I66GhiChuNhap AND @I66GhiChuNhap is not null)
	OR ([I67GhiChuXuat] = @I67GhiChuXuat AND @I67GhiChuXuat is not null)
	OR ([I68GhiChuTon] = @I68GhiChuTon AND @I68GhiChuTon is not null)
	OR ([I69GhiChuKhac] = @I69GhiChuKhac AND @I69GhiChuKhac is not null)
	OR ([Status] = @Status AND @Status is not null)
	OR ([CreatedUser] = @CreatedUser AND @CreatedUser is not null)
	OR ([Hid] = @Hid AND @Hid is not null)
	OR ([CreatedDate] = @CreatedDate AND @CreatedDate is not null)
	Select @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.PhieuNhap_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.PhieuNhap_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.PhieuNhap_Get_List
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: KVT (kvt.dyndns.org)
-- Purpose: Gets all records from the PhieuNhap table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.PhieuNhap_Get_List

AS


				
				SELECT
					[Id],
					[InputTime],
					[CreatedAt],
					[CreatedBy],
					[Latest],
					[Quantity],
					[Type],
					[Code]
				FROM
					[dbo].[PhieuNhap]
					
				Select @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.PhieuNhap_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.PhieuNhap_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.PhieuNhap_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: KVT (kvt.dyndns.org)
-- Purpose: Gets records from the PhieuNhap table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.PhieuNhap_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[Id]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [Id]'
				SET @SQL = @SQL + ', [InputTime]'
				SET @SQL = @SQL + ', [CreatedAt]'
				SET @SQL = @SQL + ', [CreatedBy]'
				SET @SQL = @SQL + ', [Latest]'
				SET @SQL = @SQL + ', [Quantity]'
				SET @SQL = @SQL + ', [Type]'
				SET @SQL = @SQL + ', [Code]'
				SET @SQL = @SQL + ' FROM [dbo].[PhieuNhap]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [Id],'
				SET @SQL = @SQL + ' [InputTime],'
				SET @SQL = @SQL + ' [CreatedAt],'
				SET @SQL = @SQL + ' [CreatedBy],'
				SET @SQL = @SQL + ' [Latest],'
				SET @SQL = @SQL + ' [Quantity],'
				SET @SQL = @SQL + ' [Type],'
				SET @SQL = @SQL + ' [Code]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				exec sp_executesql @SQL
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [dbo].[PhieuNhap]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.PhieuNhap_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.PhieuNhap_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.PhieuNhap_Insert
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: KVT (kvt.dyndns.org)
-- Purpose: Inserts a record into the PhieuNhap table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.PhieuNhap_Insert
(

	@Id int    OUTPUT,

	@InputTime datetime   ,

	@CreatedAt datetime   ,

	@CreatedBy int   ,

	@Latest int   ,

	@Quantity float   ,

	@Type nvarchar (50)  ,

	@Code nvarchar (50)  
)
AS


					
				INSERT INTO [dbo].[PhieuNhap]
					(
					[InputTime]
					,[CreatedAt]
					,[CreatedBy]
					,[Latest]
					,[Quantity]
					,[Type]
					,[Code]
					)
				VALUES
					(
					@InputTime
					,@CreatedAt
					,@CreatedBy
					,@Latest
					,@Quantity
					,@Type
					,@Code
					)
				
				-- Get the identity value
				SET @Id = SCOPE_IDENTITY()
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.PhieuNhap_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.PhieuNhap_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.PhieuNhap_Update
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: KVT (kvt.dyndns.org)
-- Purpose: Updates a record in the PhieuNhap table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.PhieuNhap_Update
(

	@Id int   ,

	@InputTime datetime   ,

	@CreatedAt datetime   ,

	@CreatedBy int   ,

	@Latest int   ,

	@Quantity float   ,

	@Type nvarchar (50)  ,

	@Code nvarchar (50)  
)
AS


				
				
				-- Modify the updatable columns
				UPDATE
					[dbo].[PhieuNhap]
				SET
					[InputTime] = @InputTime
					,[CreatedAt] = @CreatedAt
					,[CreatedBy] = @CreatedBy
					,[Latest] = @Latest
					,[Quantity] = @Quantity
					,[Type] = @Type
					,[Code] = @Code
				WHERE
[Id] = @Id 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.PhieuNhap_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.PhieuNhap_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.PhieuNhap_Delete
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: KVT (kvt.dyndns.org)
-- Purpose: Deletes a record in the PhieuNhap table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.PhieuNhap_Delete
(

	@Id int   
)
AS


				DELETE FROM [dbo].[PhieuNhap] WITH (ROWLOCK) 
				WHERE
					[Id] = @Id
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.PhieuNhap_GetByLatest procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.PhieuNhap_GetByLatest') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.PhieuNhap_GetByLatest
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: KVT (kvt.dyndns.org)
-- Purpose: Select records from the PhieuNhap table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.PhieuNhap_GetByLatest
(

	@Latest int   
)
AS


				SET ANSI_NULLS OFF
				
				SELECT
					[Id],
					[InputTime],
					[CreatedAt],
					[CreatedBy],
					[Latest],
					[Quantity],
					[Type],
					[Code]
				FROM
					[dbo].[PhieuNhap]
				WHERE
					[Latest] = @Latest
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.PhieuNhap_GetByCreatedBy procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.PhieuNhap_GetByCreatedBy') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.PhieuNhap_GetByCreatedBy
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: KVT (kvt.dyndns.org)
-- Purpose: Select records from the PhieuNhap table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.PhieuNhap_GetByCreatedBy
(

	@CreatedBy int   
)
AS


				SET ANSI_NULLS OFF
				
				SELECT
					[Id],
					[InputTime],
					[CreatedAt],
					[CreatedBy],
					[Latest],
					[Quantity],
					[Type],
					[Code]
				FROM
					[dbo].[PhieuNhap]
				WHERE
					[CreatedBy] = @CreatedBy
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.PhieuNhap_GetById procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.PhieuNhap_GetById') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.PhieuNhap_GetById
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: KVT (kvt.dyndns.org)
-- Purpose: Select records from the PhieuNhap table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.PhieuNhap_GetById
(

	@Id int   
)
AS


				SELECT
					[Id],
					[InputTime],
					[CreatedAt],
					[CreatedBy],
					[Latest],
					[Quantity],
					[Type],
					[Code]
				FROM
					[dbo].[PhieuNhap]
				WHERE
					[Id] = @Id
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.PhieuNhap_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.PhieuNhap_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.PhieuNhap_Find
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: KVT (kvt.dyndns.org)
-- Purpose: Finds records in the PhieuNhap table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.PhieuNhap_Find
(

	@SearchUsingOR bit   = null ,

	@Id int   = null ,

	@InputTime datetime   = null ,

	@CreatedAt datetime   = null ,

	@CreatedBy int   = null ,

	@Latest int   = null ,

	@Quantity float   = null ,

	@Type nvarchar (50)  = null ,

	@Code nvarchar (50)  = null 
)
AS


				
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [Id]
	, [InputTime]
	, [CreatedAt]
	, [CreatedBy]
	, [Latest]
	, [Quantity]
	, [Type]
	, [Code]
    FROM
	[dbo].[PhieuNhap]
    WHERE 
	 ([Id] = @Id OR @Id is null)
	AND ([InputTime] = @InputTime OR @InputTime is null)
	AND ([CreatedAt] = @CreatedAt OR @CreatedAt is null)
	AND ([CreatedBy] = @CreatedBy OR @CreatedBy is null)
	AND ([Latest] = @Latest OR @Latest is null)
	AND ([Quantity] = @Quantity OR @Quantity is null)
	AND ([Type] = @Type OR @Type is null)
	AND ([Code] = @Code OR @Code is null)
						
  END
  ELSE
  BEGIN
    SELECT
	  [Id]
	, [InputTime]
	, [CreatedAt]
	, [CreatedBy]
	, [Latest]
	, [Quantity]
	, [Type]
	, [Code]
    FROM
	[dbo].[PhieuNhap]
    WHERE 
	 ([Id] = @Id AND @Id is not null)
	OR ([InputTime] = @InputTime AND @InputTime is not null)
	OR ([CreatedAt] = @CreatedAt AND @CreatedAt is not null)
	OR ([CreatedBy] = @CreatedBy AND @CreatedBy is not null)
	OR ([Latest] = @Latest AND @Latest is not null)
	OR ([Quantity] = @Quantity AND @Quantity is not null)
	OR ([Type] = @Type AND @Type is not null)
	OR ([Code] = @Code AND @Code is not null)
	Select @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.Batch_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.Batch_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.Batch_Get_List
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: KVT (kvt.dyndns.org)
-- Purpose: Gets all records from the Batch table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.Batch_Get_List

AS


				
				SELECT
					[Id],
					[BatchNO],
					[Type],
					[CreatedBy],
					[CreatedAt]
				FROM
					[dbo].[Batch]
					
				Select @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.Batch_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.Batch_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.Batch_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: KVT (kvt.dyndns.org)
-- Purpose: Gets records from the Batch table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.Batch_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[Id]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [Id]'
				SET @SQL = @SQL + ', [BatchNO]'
				SET @SQL = @SQL + ', [Type]'
				SET @SQL = @SQL + ', [CreatedBy]'
				SET @SQL = @SQL + ', [CreatedAt]'
				SET @SQL = @SQL + ' FROM [dbo].[Batch]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [Id],'
				SET @SQL = @SQL + ' [BatchNO],'
				SET @SQL = @SQL + ' [Type],'
				SET @SQL = @SQL + ' [CreatedBy],'
				SET @SQL = @SQL + ' [CreatedAt]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				exec sp_executesql @SQL
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [dbo].[Batch]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.Batch_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.Batch_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.Batch_Insert
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: KVT (kvt.dyndns.org)
-- Purpose: Inserts a record into the Batch table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.Batch_Insert
(

	@Id int    OUTPUT,

	@BatchNo int   ,

	@Type int   ,

	@CreatedBy int   ,

	@CreatedAt datetime   
)
AS


					
				INSERT INTO [dbo].[Batch]
					(
					[BatchNO]
					,[Type]
					,[CreatedBy]
					,[CreatedAt]
					)
				VALUES
					(
					@BatchNo
					,@Type
					,@CreatedBy
					,@CreatedAt
					)
				
				-- Get the identity value
				SET @Id = SCOPE_IDENTITY()
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.Batch_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.Batch_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.Batch_Update
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: KVT (kvt.dyndns.org)
-- Purpose: Updates a record in the Batch table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.Batch_Update
(

	@Id int   ,

	@BatchNo int   ,

	@Type int   ,

	@CreatedBy int   ,

	@CreatedAt datetime   
)
AS


				
				
				-- Modify the updatable columns
				UPDATE
					[dbo].[Batch]
				SET
					[BatchNO] = @BatchNo
					,[Type] = @Type
					,[CreatedBy] = @CreatedBy
					,[CreatedAt] = @CreatedAt
				WHERE
[Id] = @Id 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.Batch_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.Batch_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.Batch_Delete
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: KVT (kvt.dyndns.org)
-- Purpose: Deletes a record in the Batch table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.Batch_Delete
(

	@Id int   
)
AS


				DELETE FROM [dbo].[Batch] WITH (ROWLOCK) 
				WHERE
					[Id] = @Id
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.Batch_GetByCreatedBy procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.Batch_GetByCreatedBy') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.Batch_GetByCreatedBy
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: KVT (kvt.dyndns.org)
-- Purpose: Select records from the Batch table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.Batch_GetByCreatedBy
(

	@CreatedBy int   
)
AS


				SET ANSI_NULLS OFF
				
				SELECT
					[Id],
					[BatchNO],
					[Type],
					[CreatedBy],
					[CreatedAt]
				FROM
					[dbo].[Batch]
				WHERE
					[CreatedBy] = @CreatedBy
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.Batch_GetById procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.Batch_GetById') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.Batch_GetById
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: KVT (kvt.dyndns.org)
-- Purpose: Select records from the Batch table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.Batch_GetById
(

	@Id int   
)
AS


				SELECT
					[Id],
					[BatchNO],
					[Type],
					[CreatedBy],
					[CreatedAt]
				FROM
					[dbo].[Batch]
				WHERE
					[Id] = @Id
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.Batch_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.Batch_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.Batch_Find
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: KVT (kvt.dyndns.org)
-- Purpose: Finds records in the Batch table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.Batch_Find
(

	@SearchUsingOR bit   = null ,

	@Id int   = null ,

	@BatchNo int   = null ,

	@Type int   = null ,

	@CreatedBy int   = null ,

	@CreatedAt datetime   = null 
)
AS


				
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [Id]
	, [BatchNO]
	, [Type]
	, [CreatedBy]
	, [CreatedAt]
    FROM
	[dbo].[Batch]
    WHERE 
	 ([Id] = @Id OR @Id is null)
	AND ([BatchNO] = @BatchNo OR @BatchNo is null)
	AND ([Type] = @Type OR @Type is null)
	AND ([CreatedBy] = @CreatedBy OR @CreatedBy is null)
	AND ([CreatedAt] = @CreatedAt OR @CreatedAt is null)
						
  END
  ELSE
  BEGIN
    SELECT
	  [Id]
	, [BatchNO]
	, [Type]
	, [CreatedBy]
	, [CreatedAt]
    FROM
	[dbo].[Batch]
    WHERE 
	 ([Id] = @Id AND @Id is not null)
	OR ([BatchNO] = @BatchNo AND @BatchNo is not null)
	OR ([Type] = @Type AND @Type is not null)
	OR ([CreatedBy] = @CreatedBy AND @CreatedBy is not null)
	OR ([CreatedAt] = @CreatedAt AND @CreatedAt is not null)
	Select @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.DetailBatchGPP_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.DetailBatchGPP_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.DetailBatchGPP_Get_List
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: KVT (kvt.dyndns.org)
-- Purpose: Gets all records from the DetailBatchGPP table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.DetailBatchGPP_Get_List

AS


				
				SELECT
					[Id],
					[BatchId],
					[ME1],
					[ME2],
					[IsStop],
					[CreatedAt],
					[CreatedBy],
					[Latest],
					[InputTime]
				FROM
					[dbo].[DetailBatchGPP]
					
				Select @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.DetailBatchGPP_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.DetailBatchGPP_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.DetailBatchGPP_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: KVT (kvt.dyndns.org)
-- Purpose: Gets records from the DetailBatchGPP table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.DetailBatchGPP_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[Id]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [Id]'
				SET @SQL = @SQL + ', [BatchId]'
				SET @SQL = @SQL + ', [ME1]'
				SET @SQL = @SQL + ', [ME2]'
				SET @SQL = @SQL + ', [IsStop]'
				SET @SQL = @SQL + ', [CreatedAt]'
				SET @SQL = @SQL + ', [CreatedBy]'
				SET @SQL = @SQL + ', [Latest]'
				SET @SQL = @SQL + ', [InputTime]'
				SET @SQL = @SQL + ' FROM [dbo].[DetailBatchGPP]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [Id],'
				SET @SQL = @SQL + ' [BatchId],'
				SET @SQL = @SQL + ' [ME1],'
				SET @SQL = @SQL + ' [ME2],'
				SET @SQL = @SQL + ' [IsStop],'
				SET @SQL = @SQL + ' [CreatedAt],'
				SET @SQL = @SQL + ' [CreatedBy],'
				SET @SQL = @SQL + ' [Latest],'
				SET @SQL = @SQL + ' [InputTime]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				exec sp_executesql @SQL
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [dbo].[DetailBatchGPP]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.DetailBatchGPP_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.DetailBatchGPP_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.DetailBatchGPP_Insert
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: KVT (kvt.dyndns.org)
-- Purpose: Inserts a record into the DetailBatchGPP table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.DetailBatchGPP_Insert
(

	@Id int    OUTPUT,

	@BatchId int   ,

	@Me1 int   ,

	@Me2 int   ,

	@IsStop bit   ,

	@CreatedAt datetime   ,

	@CreatedBy int   ,

	@Latest int   ,

	@InputTime datetime   
)
AS


					
				INSERT INTO [dbo].[DetailBatchGPP]
					(
					[BatchId]
					,[ME1]
					,[ME2]
					,[IsStop]
					,[CreatedAt]
					,[CreatedBy]
					,[Latest]
					,[InputTime]
					)
				VALUES
					(
					@BatchId
					,@Me1
					,@Me2
					,@IsStop
					,@CreatedAt
					,@CreatedBy
					,@Latest
					,@InputTime
					)
				
				-- Get the identity value
				SET @Id = SCOPE_IDENTITY()
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.DetailBatchGPP_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.DetailBatchGPP_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.DetailBatchGPP_Update
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: KVT (kvt.dyndns.org)
-- Purpose: Updates a record in the DetailBatchGPP table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.DetailBatchGPP_Update
(

	@Id int   ,

	@BatchId int   ,

	@Me1 int   ,

	@Me2 int   ,

	@IsStop bit   ,

	@CreatedAt datetime   ,

	@CreatedBy int   ,

	@Latest int   ,

	@InputTime datetime   
)
AS


				
				
				-- Modify the updatable columns
				UPDATE
					[dbo].[DetailBatchGPP]
				SET
					[BatchId] = @BatchId
					,[ME1] = @Me1
					,[ME2] = @Me2
					,[IsStop] = @IsStop
					,[CreatedAt] = @CreatedAt
					,[CreatedBy] = @CreatedBy
					,[Latest] = @Latest
					,[InputTime] = @InputTime
				WHERE
[Id] = @Id 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.DetailBatchGPP_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.DetailBatchGPP_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.DetailBatchGPP_Delete
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: KVT (kvt.dyndns.org)
-- Purpose: Deletes a record in the DetailBatchGPP table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.DetailBatchGPP_Delete
(

	@Id int   
)
AS


				DELETE FROM [dbo].[DetailBatchGPP] WITH (ROWLOCK) 
				WHERE
					[Id] = @Id
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.DetailBatchGPP_GetByBatchId procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.DetailBatchGPP_GetByBatchId') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.DetailBatchGPP_GetByBatchId
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: KVT (kvt.dyndns.org)
-- Purpose: Select records from the DetailBatchGPP table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.DetailBatchGPP_GetByBatchId
(

	@BatchId int   
)
AS


				SET ANSI_NULLS OFF
				
				SELECT
					[Id],
					[BatchId],
					[ME1],
					[ME2],
					[IsStop],
					[CreatedAt],
					[CreatedBy],
					[Latest],
					[InputTime]
				FROM
					[dbo].[DetailBatchGPP]
				WHERE
					[BatchId] = @BatchId
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.DetailBatchGPP_GetByLatest procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.DetailBatchGPP_GetByLatest') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.DetailBatchGPP_GetByLatest
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: KVT (kvt.dyndns.org)
-- Purpose: Select records from the DetailBatchGPP table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.DetailBatchGPP_GetByLatest
(

	@Latest int   
)
AS


				SET ANSI_NULLS OFF
				
				SELECT
					[Id],
					[BatchId],
					[ME1],
					[ME2],
					[IsStop],
					[CreatedAt],
					[CreatedBy],
					[Latest],
					[InputTime]
				FROM
					[dbo].[DetailBatchGPP]
				WHERE
					[Latest] = @Latest
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.DetailBatchGPP_GetByCreatedBy procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.DetailBatchGPP_GetByCreatedBy') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.DetailBatchGPP_GetByCreatedBy
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: KVT (kvt.dyndns.org)
-- Purpose: Select records from the DetailBatchGPP table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.DetailBatchGPP_GetByCreatedBy
(

	@CreatedBy int   
)
AS


				SET ANSI_NULLS OFF
				
				SELECT
					[Id],
					[BatchId],
					[ME1],
					[ME2],
					[IsStop],
					[CreatedAt],
					[CreatedBy],
					[Latest],
					[InputTime]
				FROM
					[dbo].[DetailBatchGPP]
				WHERE
					[CreatedBy] = @CreatedBy
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.DetailBatchGPP_GetById procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.DetailBatchGPP_GetById') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.DetailBatchGPP_GetById
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: KVT (kvt.dyndns.org)
-- Purpose: Select records from the DetailBatchGPP table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.DetailBatchGPP_GetById
(

	@Id int   
)
AS


				SELECT
					[Id],
					[BatchId],
					[ME1],
					[ME2],
					[IsStop],
					[CreatedAt],
					[CreatedBy],
					[Latest],
					[InputTime]
				FROM
					[dbo].[DetailBatchGPP]
				WHERE
					[Id] = @Id
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.DetailBatchGPP_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.DetailBatchGPP_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.DetailBatchGPP_Find
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: KVT (kvt.dyndns.org)
-- Purpose: Finds records in the DetailBatchGPP table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.DetailBatchGPP_Find
(

	@SearchUsingOR bit   = null ,

	@Id int   = null ,

	@BatchId int   = null ,

	@Me1 int   = null ,

	@Me2 int   = null ,

	@IsStop bit   = null ,

	@CreatedAt datetime   = null ,

	@CreatedBy int   = null ,

	@Latest int   = null ,

	@InputTime datetime   = null 
)
AS


				
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [Id]
	, [BatchId]
	, [ME1]
	, [ME2]
	, [IsStop]
	, [CreatedAt]
	, [CreatedBy]
	, [Latest]
	, [InputTime]
    FROM
	[dbo].[DetailBatchGPP]
    WHERE 
	 ([Id] = @Id OR @Id is null)
	AND ([BatchId] = @BatchId OR @BatchId is null)
	AND ([ME1] = @Me1 OR @Me1 is null)
	AND ([ME2] = @Me2 OR @Me2 is null)
	AND ([IsStop] = @IsStop OR @IsStop is null)
	AND ([CreatedAt] = @CreatedAt OR @CreatedAt is null)
	AND ([CreatedBy] = @CreatedBy OR @CreatedBy is null)
	AND ([Latest] = @Latest OR @Latest is null)
	AND ([InputTime] = @InputTime OR @InputTime is null)
						
  END
  ELSE
  BEGIN
    SELECT
	  [Id]
	, [BatchId]
	, [ME1]
	, [ME2]
	, [IsStop]
	, [CreatedAt]
	, [CreatedBy]
	, [Latest]
	, [InputTime]
    FROM
	[dbo].[DetailBatchGPP]
    WHERE 
	 ([Id] = @Id AND @Id is not null)
	OR ([BatchId] = @BatchId AND @BatchId is not null)
	OR ([ME1] = @Me1 AND @Me1 is not null)
	OR ([ME2] = @Me2 AND @Me2 is not null)
	OR ([IsStop] = @IsStop AND @IsStop is not null)
	OR ([CreatedAt] = @CreatedAt AND @CreatedAt is not null)
	OR ([CreatedBy] = @CreatedBy AND @CreatedBy is not null)
	OR ([Latest] = @Latest AND @Latest is not null)
	OR ([InputTime] = @InputTime AND @InputTime is not null)
	Select @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.DetailBatchTVT_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.DetailBatchTVT_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.DetailBatchTVT_Get_List
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: KVT (kvt.dyndns.org)
-- Purpose: Gets all records from the DetailBatchTVT table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.DetailBatchTVT_Get_List

AS


				
				SELECT
					[Id],
					[BatchId],
					[ME1],
					[ME2],
					[IsStop],
					[CreatedBy],
					[CreatedAt],
					[InputTime],
					[Latest]
				FROM
					[dbo].[DetailBatchTVT]
					
				Select @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.DetailBatchTVT_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.DetailBatchTVT_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.DetailBatchTVT_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: KVT (kvt.dyndns.org)
-- Purpose: Gets records from the DetailBatchTVT table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.DetailBatchTVT_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[Id]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [Id]'
				SET @SQL = @SQL + ', [BatchId]'
				SET @SQL = @SQL + ', [ME1]'
				SET @SQL = @SQL + ', [ME2]'
				SET @SQL = @SQL + ', [IsStop]'
				SET @SQL = @SQL + ', [CreatedBy]'
				SET @SQL = @SQL + ', [CreatedAt]'
				SET @SQL = @SQL + ', [InputTime]'
				SET @SQL = @SQL + ', [Latest]'
				SET @SQL = @SQL + ' FROM [dbo].[DetailBatchTVT]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [Id],'
				SET @SQL = @SQL + ' [BatchId],'
				SET @SQL = @SQL + ' [ME1],'
				SET @SQL = @SQL + ' [ME2],'
				SET @SQL = @SQL + ' [IsStop],'
				SET @SQL = @SQL + ' [CreatedBy],'
				SET @SQL = @SQL + ' [CreatedAt],'
				SET @SQL = @SQL + ' [InputTime],'
				SET @SQL = @SQL + ' [Latest]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				exec sp_executesql @SQL
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [dbo].[DetailBatchTVT]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.DetailBatchTVT_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.DetailBatchTVT_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.DetailBatchTVT_Insert
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: KVT (kvt.dyndns.org)
-- Purpose: Inserts a record into the DetailBatchTVT table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.DetailBatchTVT_Insert
(

	@Id int    OUTPUT,

	@BatchId int   ,

	@Me1 int   ,

	@Me2 int   ,

	@IsStop bit   ,

	@CreatedBy int   ,

	@CreatedAt datetime   ,

	@InputTime datetime   ,

	@Latest int   
)
AS


					
				INSERT INTO [dbo].[DetailBatchTVT]
					(
					[BatchId]
					,[ME1]
					,[ME2]
					,[IsStop]
					,[CreatedBy]
					,[CreatedAt]
					,[InputTime]
					,[Latest]
					)
				VALUES
					(
					@BatchId
					,@Me1
					,@Me2
					,@IsStop
					,@CreatedBy
					,@CreatedAt
					,@InputTime
					,@Latest
					)
				
				-- Get the identity value
				SET @Id = SCOPE_IDENTITY()
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.DetailBatchTVT_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.DetailBatchTVT_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.DetailBatchTVT_Update
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: KVT (kvt.dyndns.org)
-- Purpose: Updates a record in the DetailBatchTVT table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.DetailBatchTVT_Update
(

	@Id int   ,

	@BatchId int   ,

	@Me1 int   ,

	@Me2 int   ,

	@IsStop bit   ,

	@CreatedBy int   ,

	@CreatedAt datetime   ,

	@InputTime datetime   ,

	@Latest int   
)
AS


				
				
				-- Modify the updatable columns
				UPDATE
					[dbo].[DetailBatchTVT]
				SET
					[BatchId] = @BatchId
					,[ME1] = @Me1
					,[ME2] = @Me2
					,[IsStop] = @IsStop
					,[CreatedBy] = @CreatedBy
					,[CreatedAt] = @CreatedAt
					,[InputTime] = @InputTime
					,[Latest] = @Latest
				WHERE
[Id] = @Id 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.DetailBatchTVT_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.DetailBatchTVT_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.DetailBatchTVT_Delete
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: KVT (kvt.dyndns.org)
-- Purpose: Deletes a record in the DetailBatchTVT table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.DetailBatchTVT_Delete
(

	@Id int   
)
AS


				DELETE FROM [dbo].[DetailBatchTVT] WITH (ROWLOCK) 
				WHERE
					[Id] = @Id
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.DetailBatchTVT_GetByBatchId procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.DetailBatchTVT_GetByBatchId') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.DetailBatchTVT_GetByBatchId
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: KVT (kvt.dyndns.org)
-- Purpose: Select records from the DetailBatchTVT table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.DetailBatchTVT_GetByBatchId
(

	@BatchId int   
)
AS


				SET ANSI_NULLS OFF
				
				SELECT
					[Id],
					[BatchId],
					[ME1],
					[ME2],
					[IsStop],
					[CreatedBy],
					[CreatedAt],
					[InputTime],
					[Latest]
				FROM
					[dbo].[DetailBatchTVT]
				WHERE
					[BatchId] = @BatchId
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.DetailBatchTVT_GetByLatest procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.DetailBatchTVT_GetByLatest') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.DetailBatchTVT_GetByLatest
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: KVT (kvt.dyndns.org)
-- Purpose: Select records from the DetailBatchTVT table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.DetailBatchTVT_GetByLatest
(

	@Latest int   
)
AS


				SET ANSI_NULLS OFF
				
				SELECT
					[Id],
					[BatchId],
					[ME1],
					[ME2],
					[IsStop],
					[CreatedBy],
					[CreatedAt],
					[InputTime],
					[Latest]
				FROM
					[dbo].[DetailBatchTVT]
				WHERE
					[Latest] = @Latest
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.DetailBatchTVT_GetByCreatedBy procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.DetailBatchTVT_GetByCreatedBy') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.DetailBatchTVT_GetByCreatedBy
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: KVT (kvt.dyndns.org)
-- Purpose: Select records from the DetailBatchTVT table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.DetailBatchTVT_GetByCreatedBy
(

	@CreatedBy int   
)
AS


				SET ANSI_NULLS OFF
				
				SELECT
					[Id],
					[BatchId],
					[ME1],
					[ME2],
					[IsStop],
					[CreatedBy],
					[CreatedAt],
					[InputTime],
					[Latest]
				FROM
					[dbo].[DetailBatchTVT]
				WHERE
					[CreatedBy] = @CreatedBy
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.DetailBatchTVT_GetById procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.DetailBatchTVT_GetById') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.DetailBatchTVT_GetById
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: KVT (kvt.dyndns.org)
-- Purpose: Select records from the DetailBatchTVT table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.DetailBatchTVT_GetById
(

	@Id int   
)
AS


				SELECT
					[Id],
					[BatchId],
					[ME1],
					[ME2],
					[IsStop],
					[CreatedBy],
					[CreatedAt],
					[InputTime],
					[Latest]
				FROM
					[dbo].[DetailBatchTVT]
				WHERE
					[Id] = @Id
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.DetailBatchTVT_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.DetailBatchTVT_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.DetailBatchTVT_Find
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: KVT (kvt.dyndns.org)
-- Purpose: Finds records in the DetailBatchTVT table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.DetailBatchTVT_Find
(

	@SearchUsingOR bit   = null ,

	@Id int   = null ,

	@BatchId int   = null ,

	@Me1 int   = null ,

	@Me2 int   = null ,

	@IsStop bit   = null ,

	@CreatedBy int   = null ,

	@CreatedAt datetime   = null ,

	@InputTime datetime   = null ,

	@Latest int   = null 
)
AS


				
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [Id]
	, [BatchId]
	, [ME1]
	, [ME2]
	, [IsStop]
	, [CreatedBy]
	, [CreatedAt]
	, [InputTime]
	, [Latest]
    FROM
	[dbo].[DetailBatchTVT]
    WHERE 
	 ([Id] = @Id OR @Id is null)
	AND ([BatchId] = @BatchId OR @BatchId is null)
	AND ([ME1] = @Me1 OR @Me1 is null)
	AND ([ME2] = @Me2 OR @Me2 is null)
	AND ([IsStop] = @IsStop OR @IsStop is null)
	AND ([CreatedBy] = @CreatedBy OR @CreatedBy is null)
	AND ([CreatedAt] = @CreatedAt OR @CreatedAt is null)
	AND ([InputTime] = @InputTime OR @InputTime is null)
	AND ([Latest] = @Latest OR @Latest is null)
						
  END
  ELSE
  BEGIN
    SELECT
	  [Id]
	, [BatchId]
	, [ME1]
	, [ME2]
	, [IsStop]
	, [CreatedBy]
	, [CreatedAt]
	, [InputTime]
	, [Latest]
    FROM
	[dbo].[DetailBatchTVT]
    WHERE 
	 ([Id] = @Id AND @Id is not null)
	OR ([BatchId] = @BatchId AND @BatchId is not null)
	OR ([ME1] = @Me1 AND @Me1 is not null)
	OR ([ME2] = @Me2 AND @Me2 is not null)
	OR ([IsStop] = @IsStop AND @IsStop is not null)
	OR ([CreatedBy] = @CreatedBy AND @CreatedBy is not null)
	OR ([CreatedAt] = @CreatedAt AND @CreatedAt is not null)
	OR ([InputTime] = @InputTime AND @InputTime is not null)
	OR ([Latest] = @Latest AND @Latest is not null)
	Select @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.KVT_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.KVT_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.KVT_Get_List
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: KVT (kvt.dyndns.org)
-- Purpose: Gets all records from the KVT table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.KVT_Get_List

AS


				
				SELECT
					[Id],
					[I1InputDate],
					[I9KhiVaoDoGPPNhap],
					[I21XeBonFIQBupro],
					[I34NhapCondBH],
					[I35MeBHSoKCTV],
					[I36NhapCondBHTuTK125],
					[I37NhapLPGTuTK107],
					[I38FQIC1011],
					[I39FQIC1012],
					[I41XuatCondBHTheoMe],
					[I42XuatCondBHLenhXuatSo],
					[I43METdXuatBupro],
					[I44TankXuatBupro],
					[I45GiamDinhXuatBupro],
					[I46XuatKhacLPG],
					[I47XuatKhacCondBH],
					[I48XaDotLPG],
					[I49XaDotCondBH],
					[I52XaDotKAHXNTLPG],
					[I53XaDotKAHXNTCond],
					[I54XuatCondBHTank],
					[I55XuatCondBHGiamDinh],
					[I56TonCondBH],
					[I57TonBupro],
					[I58TenMeMNCS],
					[I59VaoDOZ3002],
					[I60RaDOZ7900],
					[I61MeMNCSSoLift],
					[I62XuatMeMNCS],
					[I63TonCondNCSTaiKCTV],
					[I64XuatCondNCSTheoTank],
					[I65XuatCondNCSTheoGiamDinh],
					[I66SuKienVanHanh],
					[I67NoteBCN],
					[I68NoteQLSPLBH],
					[I69NoteCondBHMe],
					[I70NoteGDME],
					[I71NoteMNCS],
					[Status],
					[InputUser],
					[Hid],
					[CreatedDate]
				FROM
					[dbo].[KVT]
					
				Select @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.KVT_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.KVT_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.KVT_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: KVT (kvt.dyndns.org)
-- Purpose: Gets records from the KVT table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.KVT_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[Id]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [Id]'
				SET @SQL = @SQL + ', [I1InputDate]'
				SET @SQL = @SQL + ', [I9KhiVaoDoGPPNhap]'
				SET @SQL = @SQL + ', [I21XeBonFIQBupro]'
				SET @SQL = @SQL + ', [I34NhapCondBH]'
				SET @SQL = @SQL + ', [I35MeBHSoKCTV]'
				SET @SQL = @SQL + ', [I36NhapCondBHTuTK125]'
				SET @SQL = @SQL + ', [I37NhapLPGTuTK107]'
				SET @SQL = @SQL + ', [I38FQIC1011]'
				SET @SQL = @SQL + ', [I39FQIC1012]'
				SET @SQL = @SQL + ', [I41XuatCondBHTheoMe]'
				SET @SQL = @SQL + ', [I42XuatCondBHLenhXuatSo]'
				SET @SQL = @SQL + ', [I43METdXuatBupro]'
				SET @SQL = @SQL + ', [I44TankXuatBupro]'
				SET @SQL = @SQL + ', [I45GiamDinhXuatBupro]'
				SET @SQL = @SQL + ', [I46XuatKhacLPG]'
				SET @SQL = @SQL + ', [I47XuatKhacCondBH]'
				SET @SQL = @SQL + ', [I48XaDotLPG]'
				SET @SQL = @SQL + ', [I49XaDotCondBH]'
				SET @SQL = @SQL + ', [I52XaDotKAHXNTLPG]'
				SET @SQL = @SQL + ', [I53XaDotKAHXNTCond]'
				SET @SQL = @SQL + ', [I54XuatCondBHTank]'
				SET @SQL = @SQL + ', [I55XuatCondBHGiamDinh]'
				SET @SQL = @SQL + ', [I56TonCondBH]'
				SET @SQL = @SQL + ', [I57TonBupro]'
				SET @SQL = @SQL + ', [I58TenMeMNCS]'
				SET @SQL = @SQL + ', [I59VaoDOZ3002]'
				SET @SQL = @SQL + ', [I60RaDOZ7900]'
				SET @SQL = @SQL + ', [I61MeMNCSSoLift]'
				SET @SQL = @SQL + ', [I62XuatMeMNCS]'
				SET @SQL = @SQL + ', [I63TonCondNCSTaiKCTV]'
				SET @SQL = @SQL + ', [I64XuatCondNCSTheoTank]'
				SET @SQL = @SQL + ', [I65XuatCondNCSTheoGiamDinh]'
				SET @SQL = @SQL + ', [I66SuKienVanHanh]'
				SET @SQL = @SQL + ', [I67NoteBCN]'
				SET @SQL = @SQL + ', [I68NoteQLSPLBH]'
				SET @SQL = @SQL + ', [I69NoteCondBHMe]'
				SET @SQL = @SQL + ', [I70NoteGDME]'
				SET @SQL = @SQL + ', [I71NoteMNCS]'
				SET @SQL = @SQL + ', [Status]'
				SET @SQL = @SQL + ', [InputUser]'
				SET @SQL = @SQL + ', [Hid]'
				SET @SQL = @SQL + ', [CreatedDate]'
				SET @SQL = @SQL + ' FROM [dbo].[KVT]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [Id],'
				SET @SQL = @SQL + ' [I1InputDate],'
				SET @SQL = @SQL + ' [I9KhiVaoDoGPPNhap],'
				SET @SQL = @SQL + ' [I21XeBonFIQBupro],'
				SET @SQL = @SQL + ' [I34NhapCondBH],'
				SET @SQL = @SQL + ' [I35MeBHSoKCTV],'
				SET @SQL = @SQL + ' [I36NhapCondBHTuTK125],'
				SET @SQL = @SQL + ' [I37NhapLPGTuTK107],'
				SET @SQL = @SQL + ' [I38FQIC1011],'
				SET @SQL = @SQL + ' [I39FQIC1012],'
				SET @SQL = @SQL + ' [I41XuatCondBHTheoMe],'
				SET @SQL = @SQL + ' [I42XuatCondBHLenhXuatSo],'
				SET @SQL = @SQL + ' [I43METdXuatBupro],'
				SET @SQL = @SQL + ' [I44TankXuatBupro],'
				SET @SQL = @SQL + ' [I45GiamDinhXuatBupro],'
				SET @SQL = @SQL + ' [I46XuatKhacLPG],'
				SET @SQL = @SQL + ' [I47XuatKhacCondBH],'
				SET @SQL = @SQL + ' [I48XaDotLPG],'
				SET @SQL = @SQL + ' [I49XaDotCondBH],'
				SET @SQL = @SQL + ' [I52XaDotKAHXNTLPG],'
				SET @SQL = @SQL + ' [I53XaDotKAHXNTCond],'
				SET @SQL = @SQL + ' [I54XuatCondBHTank],'
				SET @SQL = @SQL + ' [I55XuatCondBHGiamDinh],'
				SET @SQL = @SQL + ' [I56TonCondBH],'
				SET @SQL = @SQL + ' [I57TonBupro],'
				SET @SQL = @SQL + ' [I58TenMeMNCS],'
				SET @SQL = @SQL + ' [I59VaoDOZ3002],'
				SET @SQL = @SQL + ' [I60RaDOZ7900],'
				SET @SQL = @SQL + ' [I61MeMNCSSoLift],'
				SET @SQL = @SQL + ' [I62XuatMeMNCS],'
				SET @SQL = @SQL + ' [I63TonCondNCSTaiKCTV],'
				SET @SQL = @SQL + ' [I64XuatCondNCSTheoTank],'
				SET @SQL = @SQL + ' [I65XuatCondNCSTheoGiamDinh],'
				SET @SQL = @SQL + ' [I66SuKienVanHanh],'
				SET @SQL = @SQL + ' [I67NoteBCN],'
				SET @SQL = @SQL + ' [I68NoteQLSPLBH],'
				SET @SQL = @SQL + ' [I69NoteCondBHMe],'
				SET @SQL = @SQL + ' [I70NoteGDME],'
				SET @SQL = @SQL + ' [I71NoteMNCS],'
				SET @SQL = @SQL + ' [Status],'
				SET @SQL = @SQL + ' [InputUser],'
				SET @SQL = @SQL + ' [Hid],'
				SET @SQL = @SQL + ' [CreatedDate]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				exec sp_executesql @SQL
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [dbo].[KVT]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.KVT_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.KVT_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.KVT_Insert
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: KVT (kvt.dyndns.org)
-- Purpose: Inserts a record into the KVT table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.KVT_Insert
(

	@Id bigint    OUTPUT,

	@I1InputDate datetime   ,

	@I9KhiVaoDoGppNhap float   ,

	@I21XeBonFiqBupro float   ,

	@I34NhapCondBh float   ,

	@I35MeBhSoKctv float   ,

	@I36NhapCondBhTuTk125 float   ,

	@I37NhapLpgTuTk107 float   ,

	@I38Fqic1011 float   ,

	@I39Fqic1012 float   ,

	@I41XuatCondBhTheoMe float   ,

	@I42XuatCondBhLenhXuatSo nvarchar (50)  ,

	@I43MeTdXuatBupro float   ,

	@I44TankXuatBupro float   ,

	@I45GiamDinhXuatBupro float   ,

	@I46XuatKhacLpg float   ,

	@I47XuatKhacCondBh float   ,

	@I48XaDotLpg float   ,

	@I49XaDotCondBh float   ,

	@I52XaDotKahxntlpg float   ,

	@I53XaDotKahxntCond float   ,

	@I54XuatCondBhTank float   ,

	@I55XuatCondBhGiamDinh float   ,

	@I56TonCondBh float   ,

	@I57TonBupro float   ,

	@I58TenMeMncs nvarchar (50)  ,

	@I59VaoDoz3002 float   ,

	@I60RaDoz7900 float   ,

	@I61MeMncsSoLift nvarchar (50)  ,

	@I62XuatMeMncs float   ,

	@I63TonCondNcsTaiKctv float   ,

	@I64XuatCondNcsTheoTank float   ,

	@I65XuatCondNcsTheoGiamDinh float   ,

	@I66SuKienVanHanh nvarchar (500)  ,

	@I67NoteBcn nvarchar (500)  ,

	@I68NoteQlsplbh nvarchar (500)  ,

	@I69NoteCondBhMe nvarchar (500)  ,

	@I70NoteGdme nvarchar (500)  ,

	@I71NoteMncs nvarchar (500)  ,

	@Status int   ,

	@InputUser int   ,

	@Hid bigint   ,

	@CreatedDate datetime   
)
AS


					
				INSERT INTO [dbo].[KVT]
					(
					[I1InputDate]
					,[I9KhiVaoDoGPPNhap]
					,[I21XeBonFIQBupro]
					,[I34NhapCondBH]
					,[I35MeBHSoKCTV]
					,[I36NhapCondBHTuTK125]
					,[I37NhapLPGTuTK107]
					,[I38FQIC1011]
					,[I39FQIC1012]
					,[I41XuatCondBHTheoMe]
					,[I42XuatCondBHLenhXuatSo]
					,[I43METdXuatBupro]
					,[I44TankXuatBupro]
					,[I45GiamDinhXuatBupro]
					,[I46XuatKhacLPG]
					,[I47XuatKhacCondBH]
					,[I48XaDotLPG]
					,[I49XaDotCondBH]
					,[I52XaDotKAHXNTLPG]
					,[I53XaDotKAHXNTCond]
					,[I54XuatCondBHTank]
					,[I55XuatCondBHGiamDinh]
					,[I56TonCondBH]
					,[I57TonBupro]
					,[I58TenMeMNCS]
					,[I59VaoDOZ3002]
					,[I60RaDOZ7900]
					,[I61MeMNCSSoLift]
					,[I62XuatMeMNCS]
					,[I63TonCondNCSTaiKCTV]
					,[I64XuatCondNCSTheoTank]
					,[I65XuatCondNCSTheoGiamDinh]
					,[I66SuKienVanHanh]
					,[I67NoteBCN]
					,[I68NoteQLSPLBH]
					,[I69NoteCondBHMe]
					,[I70NoteGDME]
					,[I71NoteMNCS]
					,[Status]
					,[InputUser]
					,[Hid]
					,[CreatedDate]
					)
				VALUES
					(
					@I1InputDate
					,@I9KhiVaoDoGppNhap
					,@I21XeBonFiqBupro
					,@I34NhapCondBh
					,@I35MeBhSoKctv
					,@I36NhapCondBhTuTk125
					,@I37NhapLpgTuTk107
					,@I38Fqic1011
					,@I39Fqic1012
					,@I41XuatCondBhTheoMe
					,@I42XuatCondBhLenhXuatSo
					,@I43MeTdXuatBupro
					,@I44TankXuatBupro
					,@I45GiamDinhXuatBupro
					,@I46XuatKhacLpg
					,@I47XuatKhacCondBh
					,@I48XaDotLpg
					,@I49XaDotCondBh
					,@I52XaDotKahxntlpg
					,@I53XaDotKahxntCond
					,@I54XuatCondBhTank
					,@I55XuatCondBhGiamDinh
					,@I56TonCondBh
					,@I57TonBupro
					,@I58TenMeMncs
					,@I59VaoDoz3002
					,@I60RaDoz7900
					,@I61MeMncsSoLift
					,@I62XuatMeMncs
					,@I63TonCondNcsTaiKctv
					,@I64XuatCondNcsTheoTank
					,@I65XuatCondNcsTheoGiamDinh
					,@I66SuKienVanHanh
					,@I67NoteBcn
					,@I68NoteQlsplbh
					,@I69NoteCondBhMe
					,@I70NoteGdme
					,@I71NoteMncs
					,@Status
					,@InputUser
					,@Hid
					,@CreatedDate
					)
				
				-- Get the identity value
				SET @Id = SCOPE_IDENTITY()
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.KVT_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.KVT_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.KVT_Update
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: KVT (kvt.dyndns.org)
-- Purpose: Updates a record in the KVT table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.KVT_Update
(

	@Id bigint   ,

	@I1InputDate datetime   ,

	@I9KhiVaoDoGppNhap float   ,

	@I21XeBonFiqBupro float   ,

	@I34NhapCondBh float   ,

	@I35MeBhSoKctv float   ,

	@I36NhapCondBhTuTk125 float   ,

	@I37NhapLpgTuTk107 float   ,

	@I38Fqic1011 float   ,

	@I39Fqic1012 float   ,

	@I41XuatCondBhTheoMe float   ,

	@I42XuatCondBhLenhXuatSo nvarchar (50)  ,

	@I43MeTdXuatBupro float   ,

	@I44TankXuatBupro float   ,

	@I45GiamDinhXuatBupro float   ,

	@I46XuatKhacLpg float   ,

	@I47XuatKhacCondBh float   ,

	@I48XaDotLpg float   ,

	@I49XaDotCondBh float   ,

	@I52XaDotKahxntlpg float   ,

	@I53XaDotKahxntCond float   ,

	@I54XuatCondBhTank float   ,

	@I55XuatCondBhGiamDinh float   ,

	@I56TonCondBh float   ,

	@I57TonBupro float   ,

	@I58TenMeMncs nvarchar (50)  ,

	@I59VaoDoz3002 float   ,

	@I60RaDoz7900 float   ,

	@I61MeMncsSoLift nvarchar (50)  ,

	@I62XuatMeMncs float   ,

	@I63TonCondNcsTaiKctv float   ,

	@I64XuatCondNcsTheoTank float   ,

	@I65XuatCondNcsTheoGiamDinh float   ,

	@I66SuKienVanHanh nvarchar (500)  ,

	@I67NoteBcn nvarchar (500)  ,

	@I68NoteQlsplbh nvarchar (500)  ,

	@I69NoteCondBhMe nvarchar (500)  ,

	@I70NoteGdme nvarchar (500)  ,

	@I71NoteMncs nvarchar (500)  ,

	@Status int   ,

	@InputUser int   ,

	@Hid bigint   ,

	@CreatedDate datetime   
)
AS


				
				
				-- Modify the updatable columns
				UPDATE
					[dbo].[KVT]
				SET
					[I1InputDate] = @I1InputDate
					,[I9KhiVaoDoGPPNhap] = @I9KhiVaoDoGppNhap
					,[I21XeBonFIQBupro] = @I21XeBonFiqBupro
					,[I34NhapCondBH] = @I34NhapCondBh
					,[I35MeBHSoKCTV] = @I35MeBhSoKctv
					,[I36NhapCondBHTuTK125] = @I36NhapCondBhTuTk125
					,[I37NhapLPGTuTK107] = @I37NhapLpgTuTk107
					,[I38FQIC1011] = @I38Fqic1011
					,[I39FQIC1012] = @I39Fqic1012
					,[I41XuatCondBHTheoMe] = @I41XuatCondBhTheoMe
					,[I42XuatCondBHLenhXuatSo] = @I42XuatCondBhLenhXuatSo
					,[I43METdXuatBupro] = @I43MeTdXuatBupro
					,[I44TankXuatBupro] = @I44TankXuatBupro
					,[I45GiamDinhXuatBupro] = @I45GiamDinhXuatBupro
					,[I46XuatKhacLPG] = @I46XuatKhacLpg
					,[I47XuatKhacCondBH] = @I47XuatKhacCondBh
					,[I48XaDotLPG] = @I48XaDotLpg
					,[I49XaDotCondBH] = @I49XaDotCondBh
					,[I52XaDotKAHXNTLPG] = @I52XaDotKahxntlpg
					,[I53XaDotKAHXNTCond] = @I53XaDotKahxntCond
					,[I54XuatCondBHTank] = @I54XuatCondBhTank
					,[I55XuatCondBHGiamDinh] = @I55XuatCondBhGiamDinh
					,[I56TonCondBH] = @I56TonCondBh
					,[I57TonBupro] = @I57TonBupro
					,[I58TenMeMNCS] = @I58TenMeMncs
					,[I59VaoDOZ3002] = @I59VaoDoz3002
					,[I60RaDOZ7900] = @I60RaDoz7900
					,[I61MeMNCSSoLift] = @I61MeMncsSoLift
					,[I62XuatMeMNCS] = @I62XuatMeMncs
					,[I63TonCondNCSTaiKCTV] = @I63TonCondNcsTaiKctv
					,[I64XuatCondNCSTheoTank] = @I64XuatCondNcsTheoTank
					,[I65XuatCondNCSTheoGiamDinh] = @I65XuatCondNcsTheoGiamDinh
					,[I66SuKienVanHanh] = @I66SuKienVanHanh
					,[I67NoteBCN] = @I67NoteBcn
					,[I68NoteQLSPLBH] = @I68NoteQlsplbh
					,[I69NoteCondBHMe] = @I69NoteCondBhMe
					,[I70NoteGDME] = @I70NoteGdme
					,[I71NoteMNCS] = @I71NoteMncs
					,[Status] = @Status
					,[InputUser] = @InputUser
					,[Hid] = @Hid
					,[CreatedDate] = @CreatedDate
				WHERE
[Id] = @Id 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.KVT_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.KVT_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.KVT_Delete
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: KVT (kvt.dyndns.org)
-- Purpose: Deletes a record in the KVT table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.KVT_Delete
(

	@Id bigint   
)
AS


				DELETE FROM [dbo].[KVT] WITH (ROWLOCK) 
				WHERE
					[Id] = @Id
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.KVT_GetByStatus procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.KVT_GetByStatus') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.KVT_GetByStatus
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: KVT (kvt.dyndns.org)
-- Purpose: Select records from the KVT table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.KVT_GetByStatus
(

	@Status int   
)
AS


				SET ANSI_NULLS OFF
				
				SELECT
					[Id],
					[I1InputDate],
					[I9KhiVaoDoGPPNhap],
					[I21XeBonFIQBupro],
					[I34NhapCondBH],
					[I35MeBHSoKCTV],
					[I36NhapCondBHTuTK125],
					[I37NhapLPGTuTK107],
					[I38FQIC1011],
					[I39FQIC1012],
					[I41XuatCondBHTheoMe],
					[I42XuatCondBHLenhXuatSo],
					[I43METdXuatBupro],
					[I44TankXuatBupro],
					[I45GiamDinhXuatBupro],
					[I46XuatKhacLPG],
					[I47XuatKhacCondBH],
					[I48XaDotLPG],
					[I49XaDotCondBH],
					[I52XaDotKAHXNTLPG],
					[I53XaDotKAHXNTCond],
					[I54XuatCondBHTank],
					[I55XuatCondBHGiamDinh],
					[I56TonCondBH],
					[I57TonBupro],
					[I58TenMeMNCS],
					[I59VaoDOZ3002],
					[I60RaDOZ7900],
					[I61MeMNCSSoLift],
					[I62XuatMeMNCS],
					[I63TonCondNCSTaiKCTV],
					[I64XuatCondNCSTheoTank],
					[I65XuatCondNCSTheoGiamDinh],
					[I66SuKienVanHanh],
					[I67NoteBCN],
					[I68NoteQLSPLBH],
					[I69NoteCondBHMe],
					[I70NoteGDME],
					[I71NoteMNCS],
					[Status],
					[InputUser],
					[Hid],
					[CreatedDate]
				FROM
					[dbo].[KVT]
				WHERE
					[Status] = @Status
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.KVT_GetByInputUser procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.KVT_GetByInputUser') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.KVT_GetByInputUser
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: KVT (kvt.dyndns.org)
-- Purpose: Select records from the KVT table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.KVT_GetByInputUser
(

	@InputUser int   
)
AS


				SET ANSI_NULLS OFF
				
				SELECT
					[Id],
					[I1InputDate],
					[I9KhiVaoDoGPPNhap],
					[I21XeBonFIQBupro],
					[I34NhapCondBH],
					[I35MeBHSoKCTV],
					[I36NhapCondBHTuTK125],
					[I37NhapLPGTuTK107],
					[I38FQIC1011],
					[I39FQIC1012],
					[I41XuatCondBHTheoMe],
					[I42XuatCondBHLenhXuatSo],
					[I43METdXuatBupro],
					[I44TankXuatBupro],
					[I45GiamDinhXuatBupro],
					[I46XuatKhacLPG],
					[I47XuatKhacCondBH],
					[I48XaDotLPG],
					[I49XaDotCondBH],
					[I52XaDotKAHXNTLPG],
					[I53XaDotKAHXNTCond],
					[I54XuatCondBHTank],
					[I55XuatCondBHGiamDinh],
					[I56TonCondBH],
					[I57TonBupro],
					[I58TenMeMNCS],
					[I59VaoDOZ3002],
					[I60RaDOZ7900],
					[I61MeMNCSSoLift],
					[I62XuatMeMNCS],
					[I63TonCondNCSTaiKCTV],
					[I64XuatCondNCSTheoTank],
					[I65XuatCondNCSTheoGiamDinh],
					[I66SuKienVanHanh],
					[I67NoteBCN],
					[I68NoteQLSPLBH],
					[I69NoteCondBHMe],
					[I70NoteGDME],
					[I71NoteMNCS],
					[Status],
					[InputUser],
					[Hid],
					[CreatedDate]
				FROM
					[dbo].[KVT]
				WHERE
					[InputUser] = @InputUser
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.KVT_GetByHid procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.KVT_GetByHid') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.KVT_GetByHid
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: KVT (kvt.dyndns.org)
-- Purpose: Select records from the KVT table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.KVT_GetByHid
(

	@Hid bigint   
)
AS


				SET ANSI_NULLS OFF
				
				SELECT
					[Id],
					[I1InputDate],
					[I9KhiVaoDoGPPNhap],
					[I21XeBonFIQBupro],
					[I34NhapCondBH],
					[I35MeBHSoKCTV],
					[I36NhapCondBHTuTK125],
					[I37NhapLPGTuTK107],
					[I38FQIC1011],
					[I39FQIC1012],
					[I41XuatCondBHTheoMe],
					[I42XuatCondBHLenhXuatSo],
					[I43METdXuatBupro],
					[I44TankXuatBupro],
					[I45GiamDinhXuatBupro],
					[I46XuatKhacLPG],
					[I47XuatKhacCondBH],
					[I48XaDotLPG],
					[I49XaDotCondBH],
					[I52XaDotKAHXNTLPG],
					[I53XaDotKAHXNTCond],
					[I54XuatCondBHTank],
					[I55XuatCondBHGiamDinh],
					[I56TonCondBH],
					[I57TonBupro],
					[I58TenMeMNCS],
					[I59VaoDOZ3002],
					[I60RaDOZ7900],
					[I61MeMNCSSoLift],
					[I62XuatMeMNCS],
					[I63TonCondNCSTaiKCTV],
					[I64XuatCondNCSTheoTank],
					[I65XuatCondNCSTheoGiamDinh],
					[I66SuKienVanHanh],
					[I67NoteBCN],
					[I68NoteQLSPLBH],
					[I69NoteCondBHMe],
					[I70NoteGDME],
					[I71NoteMNCS],
					[Status],
					[InputUser],
					[Hid],
					[CreatedDate]
				FROM
					[dbo].[KVT]
				WHERE
					[Hid] = @Hid
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.KVT_GetById procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.KVT_GetById') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.KVT_GetById
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: KVT (kvt.dyndns.org)
-- Purpose: Select records from the KVT table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.KVT_GetById
(

	@Id bigint   
)
AS


				SELECT
					[Id],
					[I1InputDate],
					[I9KhiVaoDoGPPNhap],
					[I21XeBonFIQBupro],
					[I34NhapCondBH],
					[I35MeBHSoKCTV],
					[I36NhapCondBHTuTK125],
					[I37NhapLPGTuTK107],
					[I38FQIC1011],
					[I39FQIC1012],
					[I41XuatCondBHTheoMe],
					[I42XuatCondBHLenhXuatSo],
					[I43METdXuatBupro],
					[I44TankXuatBupro],
					[I45GiamDinhXuatBupro],
					[I46XuatKhacLPG],
					[I47XuatKhacCondBH],
					[I48XaDotLPG],
					[I49XaDotCondBH],
					[I52XaDotKAHXNTLPG],
					[I53XaDotKAHXNTCond],
					[I54XuatCondBHTank],
					[I55XuatCondBHGiamDinh],
					[I56TonCondBH],
					[I57TonBupro],
					[I58TenMeMNCS],
					[I59VaoDOZ3002],
					[I60RaDOZ7900],
					[I61MeMNCSSoLift],
					[I62XuatMeMNCS],
					[I63TonCondNCSTaiKCTV],
					[I64XuatCondNCSTheoTank],
					[I65XuatCondNCSTheoGiamDinh],
					[I66SuKienVanHanh],
					[I67NoteBCN],
					[I68NoteQLSPLBH],
					[I69NoteCondBHMe],
					[I70NoteGDME],
					[I71NoteMNCS],
					[Status],
					[InputUser],
					[Hid],
					[CreatedDate]
				FROM
					[dbo].[KVT]
				WHERE
					[Id] = @Id
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.KVT_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.KVT_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.KVT_Find
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: KVT (kvt.dyndns.org)
-- Purpose: Finds records in the KVT table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.KVT_Find
(

	@SearchUsingOR bit   = null ,

	@Id bigint   = null ,

	@I1InputDate datetime   = null ,

	@I9KhiVaoDoGppNhap float   = null ,

	@I21XeBonFiqBupro float   = null ,

	@I34NhapCondBh float   = null ,

	@I35MeBhSoKctv float   = null ,

	@I36NhapCondBhTuTk125 float   = null ,

	@I37NhapLpgTuTk107 float   = null ,

	@I38Fqic1011 float   = null ,

	@I39Fqic1012 float   = null ,

	@I41XuatCondBhTheoMe float   = null ,

	@I42XuatCondBhLenhXuatSo nvarchar (50)  = null ,

	@I43MeTdXuatBupro float   = null ,

	@I44TankXuatBupro float   = null ,

	@I45GiamDinhXuatBupro float   = null ,

	@I46XuatKhacLpg float   = null ,

	@I47XuatKhacCondBh float   = null ,

	@I48XaDotLpg float   = null ,

	@I49XaDotCondBh float   = null ,

	@I52XaDotKahxntlpg float   = null ,

	@I53XaDotKahxntCond float   = null ,

	@I54XuatCondBhTank float   = null ,

	@I55XuatCondBhGiamDinh float   = null ,

	@I56TonCondBh float   = null ,

	@I57TonBupro float   = null ,

	@I58TenMeMncs nvarchar (50)  = null ,

	@I59VaoDoz3002 float   = null ,

	@I60RaDoz7900 float   = null ,

	@I61MeMncsSoLift nvarchar (50)  = null ,

	@I62XuatMeMncs float   = null ,

	@I63TonCondNcsTaiKctv float   = null ,

	@I64XuatCondNcsTheoTank float   = null ,

	@I65XuatCondNcsTheoGiamDinh float   = null ,

	@I66SuKienVanHanh nvarchar (500)  = null ,

	@I67NoteBcn nvarchar (500)  = null ,

	@I68NoteQlsplbh nvarchar (500)  = null ,

	@I69NoteCondBhMe nvarchar (500)  = null ,

	@I70NoteGdme nvarchar (500)  = null ,

	@I71NoteMncs nvarchar (500)  = null ,

	@Status int   = null ,

	@InputUser int   = null ,

	@Hid bigint   = null ,

	@CreatedDate datetime   = null 
)
AS


				
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [Id]
	, [I1InputDate]
	, [I9KhiVaoDoGPPNhap]
	, [I21XeBonFIQBupro]
	, [I34NhapCondBH]
	, [I35MeBHSoKCTV]
	, [I36NhapCondBHTuTK125]
	, [I37NhapLPGTuTK107]
	, [I38FQIC1011]
	, [I39FQIC1012]
	, [I41XuatCondBHTheoMe]
	, [I42XuatCondBHLenhXuatSo]
	, [I43METdXuatBupro]
	, [I44TankXuatBupro]
	, [I45GiamDinhXuatBupro]
	, [I46XuatKhacLPG]
	, [I47XuatKhacCondBH]
	, [I48XaDotLPG]
	, [I49XaDotCondBH]
	, [I52XaDotKAHXNTLPG]
	, [I53XaDotKAHXNTCond]
	, [I54XuatCondBHTank]
	, [I55XuatCondBHGiamDinh]
	, [I56TonCondBH]
	, [I57TonBupro]
	, [I58TenMeMNCS]
	, [I59VaoDOZ3002]
	, [I60RaDOZ7900]
	, [I61MeMNCSSoLift]
	, [I62XuatMeMNCS]
	, [I63TonCondNCSTaiKCTV]
	, [I64XuatCondNCSTheoTank]
	, [I65XuatCondNCSTheoGiamDinh]
	, [I66SuKienVanHanh]
	, [I67NoteBCN]
	, [I68NoteQLSPLBH]
	, [I69NoteCondBHMe]
	, [I70NoteGDME]
	, [I71NoteMNCS]
	, [Status]
	, [InputUser]
	, [Hid]
	, [CreatedDate]
    FROM
	[dbo].[KVT]
    WHERE 
	 ([Id] = @Id OR @Id is null)
	AND ([I1InputDate] = @I1InputDate OR @I1InputDate is null)
	AND ([I9KhiVaoDoGPPNhap] = @I9KhiVaoDoGppNhap OR @I9KhiVaoDoGppNhap is null)
	AND ([I21XeBonFIQBupro] = @I21XeBonFiqBupro OR @I21XeBonFiqBupro is null)
	AND ([I34NhapCondBH] = @I34NhapCondBh OR @I34NhapCondBh is null)
	AND ([I35MeBHSoKCTV] = @I35MeBhSoKctv OR @I35MeBhSoKctv is null)
	AND ([I36NhapCondBHTuTK125] = @I36NhapCondBhTuTk125 OR @I36NhapCondBhTuTk125 is null)
	AND ([I37NhapLPGTuTK107] = @I37NhapLpgTuTk107 OR @I37NhapLpgTuTk107 is null)
	AND ([I38FQIC1011] = @I38Fqic1011 OR @I38Fqic1011 is null)
	AND ([I39FQIC1012] = @I39Fqic1012 OR @I39Fqic1012 is null)
	AND ([I41XuatCondBHTheoMe] = @I41XuatCondBhTheoMe OR @I41XuatCondBhTheoMe is null)
	AND ([I42XuatCondBHLenhXuatSo] = @I42XuatCondBhLenhXuatSo OR @I42XuatCondBhLenhXuatSo is null)
	AND ([I43METdXuatBupro] = @I43MeTdXuatBupro OR @I43MeTdXuatBupro is null)
	AND ([I44TankXuatBupro] = @I44TankXuatBupro OR @I44TankXuatBupro is null)
	AND ([I45GiamDinhXuatBupro] = @I45GiamDinhXuatBupro OR @I45GiamDinhXuatBupro is null)
	AND ([I46XuatKhacLPG] = @I46XuatKhacLpg OR @I46XuatKhacLpg is null)
	AND ([I47XuatKhacCondBH] = @I47XuatKhacCondBh OR @I47XuatKhacCondBh is null)
	AND ([I48XaDotLPG] = @I48XaDotLpg OR @I48XaDotLpg is null)
	AND ([I49XaDotCondBH] = @I49XaDotCondBh OR @I49XaDotCondBh is null)
	AND ([I52XaDotKAHXNTLPG] = @I52XaDotKahxntlpg OR @I52XaDotKahxntlpg is null)
	AND ([I53XaDotKAHXNTCond] = @I53XaDotKahxntCond OR @I53XaDotKahxntCond is null)
	AND ([I54XuatCondBHTank] = @I54XuatCondBhTank OR @I54XuatCondBhTank is null)
	AND ([I55XuatCondBHGiamDinh] = @I55XuatCondBhGiamDinh OR @I55XuatCondBhGiamDinh is null)
	AND ([I56TonCondBH] = @I56TonCondBh OR @I56TonCondBh is null)
	AND ([I57TonBupro] = @I57TonBupro OR @I57TonBupro is null)
	AND ([I58TenMeMNCS] = @I58TenMeMncs OR @I58TenMeMncs is null)
	AND ([I59VaoDOZ3002] = @I59VaoDoz3002 OR @I59VaoDoz3002 is null)
	AND ([I60RaDOZ7900] = @I60RaDoz7900 OR @I60RaDoz7900 is null)
	AND ([I61MeMNCSSoLift] = @I61MeMncsSoLift OR @I61MeMncsSoLift is null)
	AND ([I62XuatMeMNCS] = @I62XuatMeMncs OR @I62XuatMeMncs is null)
	AND ([I63TonCondNCSTaiKCTV] = @I63TonCondNcsTaiKctv OR @I63TonCondNcsTaiKctv is null)
	AND ([I64XuatCondNCSTheoTank] = @I64XuatCondNcsTheoTank OR @I64XuatCondNcsTheoTank is null)
	AND ([I65XuatCondNCSTheoGiamDinh] = @I65XuatCondNcsTheoGiamDinh OR @I65XuatCondNcsTheoGiamDinh is null)
	AND ([I66SuKienVanHanh] = @I66SuKienVanHanh OR @I66SuKienVanHanh is null)
	AND ([I67NoteBCN] = @I67NoteBcn OR @I67NoteBcn is null)
	AND ([I68NoteQLSPLBH] = @I68NoteQlsplbh OR @I68NoteQlsplbh is null)
	AND ([I69NoteCondBHMe] = @I69NoteCondBhMe OR @I69NoteCondBhMe is null)
	AND ([I70NoteGDME] = @I70NoteGdme OR @I70NoteGdme is null)
	AND ([I71NoteMNCS] = @I71NoteMncs OR @I71NoteMncs is null)
	AND ([Status] = @Status OR @Status is null)
	AND ([InputUser] = @InputUser OR @InputUser is null)
	AND ([Hid] = @Hid OR @Hid is null)
	AND ([CreatedDate] = @CreatedDate OR @CreatedDate is null)
						
  END
  ELSE
  BEGIN
    SELECT
	  [Id]
	, [I1InputDate]
	, [I9KhiVaoDoGPPNhap]
	, [I21XeBonFIQBupro]
	, [I34NhapCondBH]
	, [I35MeBHSoKCTV]
	, [I36NhapCondBHTuTK125]
	, [I37NhapLPGTuTK107]
	, [I38FQIC1011]
	, [I39FQIC1012]
	, [I41XuatCondBHTheoMe]
	, [I42XuatCondBHLenhXuatSo]
	, [I43METdXuatBupro]
	, [I44TankXuatBupro]
	, [I45GiamDinhXuatBupro]
	, [I46XuatKhacLPG]
	, [I47XuatKhacCondBH]
	, [I48XaDotLPG]
	, [I49XaDotCondBH]
	, [I52XaDotKAHXNTLPG]
	, [I53XaDotKAHXNTCond]
	, [I54XuatCondBHTank]
	, [I55XuatCondBHGiamDinh]
	, [I56TonCondBH]
	, [I57TonBupro]
	, [I58TenMeMNCS]
	, [I59VaoDOZ3002]
	, [I60RaDOZ7900]
	, [I61MeMNCSSoLift]
	, [I62XuatMeMNCS]
	, [I63TonCondNCSTaiKCTV]
	, [I64XuatCondNCSTheoTank]
	, [I65XuatCondNCSTheoGiamDinh]
	, [I66SuKienVanHanh]
	, [I67NoteBCN]
	, [I68NoteQLSPLBH]
	, [I69NoteCondBHMe]
	, [I70NoteGDME]
	, [I71NoteMNCS]
	, [Status]
	, [InputUser]
	, [Hid]
	, [CreatedDate]
    FROM
	[dbo].[KVT]
    WHERE 
	 ([Id] = @Id AND @Id is not null)
	OR ([I1InputDate] = @I1InputDate AND @I1InputDate is not null)
	OR ([I9KhiVaoDoGPPNhap] = @I9KhiVaoDoGppNhap AND @I9KhiVaoDoGppNhap is not null)
	OR ([I21XeBonFIQBupro] = @I21XeBonFiqBupro AND @I21XeBonFiqBupro is not null)
	OR ([I34NhapCondBH] = @I34NhapCondBh AND @I34NhapCondBh is not null)
	OR ([I35MeBHSoKCTV] = @I35MeBhSoKctv AND @I35MeBhSoKctv is not null)
	OR ([I36NhapCondBHTuTK125] = @I36NhapCondBhTuTk125 AND @I36NhapCondBhTuTk125 is not null)
	OR ([I37NhapLPGTuTK107] = @I37NhapLpgTuTk107 AND @I37NhapLpgTuTk107 is not null)
	OR ([I38FQIC1011] = @I38Fqic1011 AND @I38Fqic1011 is not null)
	OR ([I39FQIC1012] = @I39Fqic1012 AND @I39Fqic1012 is not null)
	OR ([I41XuatCondBHTheoMe] = @I41XuatCondBhTheoMe AND @I41XuatCondBhTheoMe is not null)
	OR ([I42XuatCondBHLenhXuatSo] = @I42XuatCondBhLenhXuatSo AND @I42XuatCondBhLenhXuatSo is not null)
	OR ([I43METdXuatBupro] = @I43MeTdXuatBupro AND @I43MeTdXuatBupro is not null)
	OR ([I44TankXuatBupro] = @I44TankXuatBupro AND @I44TankXuatBupro is not null)
	OR ([I45GiamDinhXuatBupro] = @I45GiamDinhXuatBupro AND @I45GiamDinhXuatBupro is not null)
	OR ([I46XuatKhacLPG] = @I46XuatKhacLpg AND @I46XuatKhacLpg is not null)
	OR ([I47XuatKhacCondBH] = @I47XuatKhacCondBh AND @I47XuatKhacCondBh is not null)
	OR ([I48XaDotLPG] = @I48XaDotLpg AND @I48XaDotLpg is not null)
	OR ([I49XaDotCondBH] = @I49XaDotCondBh AND @I49XaDotCondBh is not null)
	OR ([I52XaDotKAHXNTLPG] = @I52XaDotKahxntlpg AND @I52XaDotKahxntlpg is not null)
	OR ([I53XaDotKAHXNTCond] = @I53XaDotKahxntCond AND @I53XaDotKahxntCond is not null)
	OR ([I54XuatCondBHTank] = @I54XuatCondBhTank AND @I54XuatCondBhTank is not null)
	OR ([I55XuatCondBHGiamDinh] = @I55XuatCondBhGiamDinh AND @I55XuatCondBhGiamDinh is not null)
	OR ([I56TonCondBH] = @I56TonCondBh AND @I56TonCondBh is not null)
	OR ([I57TonBupro] = @I57TonBupro AND @I57TonBupro is not null)
	OR ([I58TenMeMNCS] = @I58TenMeMncs AND @I58TenMeMncs is not null)
	OR ([I59VaoDOZ3002] = @I59VaoDoz3002 AND @I59VaoDoz3002 is not null)
	OR ([I60RaDOZ7900] = @I60RaDoz7900 AND @I60RaDoz7900 is not null)
	OR ([I61MeMNCSSoLift] = @I61MeMncsSoLift AND @I61MeMncsSoLift is not null)
	OR ([I62XuatMeMNCS] = @I62XuatMeMncs AND @I62XuatMeMncs is not null)
	OR ([I63TonCondNCSTaiKCTV] = @I63TonCondNcsTaiKctv AND @I63TonCondNcsTaiKctv is not null)
	OR ([I64XuatCondNCSTheoTank] = @I64XuatCondNcsTheoTank AND @I64XuatCondNcsTheoTank is not null)
	OR ([I65XuatCondNCSTheoGiamDinh] = @I65XuatCondNcsTheoGiamDinh AND @I65XuatCondNcsTheoGiamDinh is not null)
	OR ([I66SuKienVanHanh] = @I66SuKienVanHanh AND @I66SuKienVanHanh is not null)
	OR ([I67NoteBCN] = @I67NoteBcn AND @I67NoteBcn is not null)
	OR ([I68NoteQLSPLBH] = @I68NoteQlsplbh AND @I68NoteQlsplbh is not null)
	OR ([I69NoteCondBHMe] = @I69NoteCondBhMe AND @I69NoteCondBhMe is not null)
	OR ([I70NoteGDME] = @I70NoteGdme AND @I70NoteGdme is not null)
	OR ([I71NoteMNCS] = @I71NoteMncs AND @I71NoteMncs is not null)
	OR ([Status] = @Status AND @Status is not null)
	OR ([InputUser] = @InputUser AND @InputUser is not null)
	OR ([Hid] = @Hid AND @Hid is not null)
	OR ([CreatedDate] = @CreatedDate AND @CreatedDate is not null)
	Select @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.GPP_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.GPP_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.GPP_Get_List
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: KVT (kvt.dyndns.org)
-- Purpose: Gets all records from the GPP table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.GPP_Get_List

AS


				
				SELECT
					[Id],
					[I1InputDate],
					[I2KhiAm],
					[I3Cond],
					[I4P_CCP],
					[I6PI0101],
					[I7FIQ0401],
					[I8FIQ0301],
					[I9FIQ0302],
					[I10FI102ByPass],
					[I11FIQ2601_0h],
					[I12FIQ2601_24h],
					[I13FIQ2601_DA],
					[I14FIQ2602_0h],
					[I15FIQ2602_24h],
					[I16FIQ2602_DA],
					[I17FIQ2603_0h],
					[I18FIQ2603_24h],
					[I19FIQ2603_DA],
					[I20XeBon],
					[I21FIQ2402],
					[I22ME24_0h],
					[I23ME24_24h],
					[I24TenMeCondBH],
					[I25ME25_0h],
					[I26ME25_24h],
					[I27ME26_0h],
					[I28ME26_24h],
					[I29KCTV_nhan_LPG],
					[I30KCTV_nhan_Cond],
					[I31ApSuat],
					[I32ME13A],
					[I33ME13B],
					[I34FIQ5801],
					[I35V21A_MucBon],
					[I36V21B_MucBon],
					[I37V21C_MucBon],
					[I38TK21_MucBon],
					[I109NoteBCN],
					[I110NoteSPLBH],
					[I111NoteMeCondBH],
					[I112NoteMeCondNCS],
					[Status],
					[InputUser],
					[Hid],
					[CreatedDate]
				FROM
					[dbo].[GPP]
					
				Select @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.GPP_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.GPP_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.GPP_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: KVT (kvt.dyndns.org)
-- Purpose: Gets records from the GPP table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.GPP_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				IF (@OrderBy is null or LEN(@OrderBy) < 1)
				BEGIN
					-- default order by to first column
					SET @OrderBy = '[Id]'
				END

				-- SQL Server 2005 Paging
				declare @SQL as nvarchar(4000)
				SET @SQL = 'WITH PageIndex AS ('
				SET @SQL = @SQL + ' SELECT'
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ROW_NUMBER() OVER (ORDER BY ' + @OrderBy + ') as RowIndex'
				SET @SQL = @SQL + ', [Id]'
				SET @SQL = @SQL + ', [I1InputDate]'
				SET @SQL = @SQL + ', [I2KhiAm]'
				SET @SQL = @SQL + ', [I3Cond]'
				SET @SQL = @SQL + ', [I4P_CCP]'
				SET @SQL = @SQL + ', [I6PI0101]'
				SET @SQL = @SQL + ', [I7FIQ0401]'
				SET @SQL = @SQL + ', [I8FIQ0301]'
				SET @SQL = @SQL + ', [I9FIQ0302]'
				SET @SQL = @SQL + ', [I10FI102ByPass]'
				SET @SQL = @SQL + ', [I11FIQ2601_0h]'
				SET @SQL = @SQL + ', [I12FIQ2601_24h]'
				SET @SQL = @SQL + ', [I13FIQ2601_DA]'
				SET @SQL = @SQL + ', [I14FIQ2602_0h]'
				SET @SQL = @SQL + ', [I15FIQ2602_24h]'
				SET @SQL = @SQL + ', [I16FIQ2602_DA]'
				SET @SQL = @SQL + ', [I17FIQ2603_0h]'
				SET @SQL = @SQL + ', [I18FIQ2603_24h]'
				SET @SQL = @SQL + ', [I19FIQ2603_DA]'
				SET @SQL = @SQL + ', [I20XeBon]'
				SET @SQL = @SQL + ', [I21FIQ2402]'
				SET @SQL = @SQL + ', [I22ME24_0h]'
				SET @SQL = @SQL + ', [I23ME24_24h]'
				SET @SQL = @SQL + ', [I24TenMeCondBH]'
				SET @SQL = @SQL + ', [I25ME25_0h]'
				SET @SQL = @SQL + ', [I26ME25_24h]'
				SET @SQL = @SQL + ', [I27ME26_0h]'
				SET @SQL = @SQL + ', [I28ME26_24h]'
				SET @SQL = @SQL + ', [I29KCTV_nhan_LPG]'
				SET @SQL = @SQL + ', [I30KCTV_nhan_Cond]'
				SET @SQL = @SQL + ', [I31ApSuat]'
				SET @SQL = @SQL + ', [I32ME13A]'
				SET @SQL = @SQL + ', [I33ME13B]'
				SET @SQL = @SQL + ', [I34FIQ5801]'
				SET @SQL = @SQL + ', [I35V21A_MucBon]'
				SET @SQL = @SQL + ', [I36V21B_MucBon]'
				SET @SQL = @SQL + ', [I37V21C_MucBon]'
				SET @SQL = @SQL + ', [I38TK21_MucBon]'
				SET @SQL = @SQL + ', [I109NoteBCN]'
				SET @SQL = @SQL + ', [I110NoteSPLBH]'
				SET @SQL = @SQL + ', [I111NoteMeCondBH]'
				SET @SQL = @SQL + ', [I112NoteMeCondNCS]'
				SET @SQL = @SQL + ', [Status]'
				SET @SQL = @SQL + ', [InputUser]'
				SET @SQL = @SQL + ', [Hid]'
				SET @SQL = @SQL + ', [CreatedDate]'
				SET @SQL = @SQL + ' FROM [dbo].[GPP]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				SET @SQL = @SQL + ' ) SELECT'
				SET @SQL = @SQL + ' [Id],'
				SET @SQL = @SQL + ' [I1InputDate],'
				SET @SQL = @SQL + ' [I2KhiAm],'
				SET @SQL = @SQL + ' [I3Cond],'
				SET @SQL = @SQL + ' [I4P_CCP],'
				SET @SQL = @SQL + ' [I6PI0101],'
				SET @SQL = @SQL + ' [I7FIQ0401],'
				SET @SQL = @SQL + ' [I8FIQ0301],'
				SET @SQL = @SQL + ' [I9FIQ0302],'
				SET @SQL = @SQL + ' [I10FI102ByPass],'
				SET @SQL = @SQL + ' [I11FIQ2601_0h],'
				SET @SQL = @SQL + ' [I12FIQ2601_24h],'
				SET @SQL = @SQL + ' [I13FIQ2601_DA],'
				SET @SQL = @SQL + ' [I14FIQ2602_0h],'
				SET @SQL = @SQL + ' [I15FIQ2602_24h],'
				SET @SQL = @SQL + ' [I16FIQ2602_DA],'
				SET @SQL = @SQL + ' [I17FIQ2603_0h],'
				SET @SQL = @SQL + ' [I18FIQ2603_24h],'
				SET @SQL = @SQL + ' [I19FIQ2603_DA],'
				SET @SQL = @SQL + ' [I20XeBon],'
				SET @SQL = @SQL + ' [I21FIQ2402],'
				SET @SQL = @SQL + ' [I22ME24_0h],'
				SET @SQL = @SQL + ' [I23ME24_24h],'
				SET @SQL = @SQL + ' [I24TenMeCondBH],'
				SET @SQL = @SQL + ' [I25ME25_0h],'
				SET @SQL = @SQL + ' [I26ME25_24h],'
				SET @SQL = @SQL + ' [I27ME26_0h],'
				SET @SQL = @SQL + ' [I28ME26_24h],'
				SET @SQL = @SQL + ' [I29KCTV_nhan_LPG],'
				SET @SQL = @SQL + ' [I30KCTV_nhan_Cond],'
				SET @SQL = @SQL + ' [I31ApSuat],'
				SET @SQL = @SQL + ' [I32ME13A],'
				SET @SQL = @SQL + ' [I33ME13B],'
				SET @SQL = @SQL + ' [I34FIQ5801],'
				SET @SQL = @SQL + ' [I35V21A_MucBon],'
				SET @SQL = @SQL + ' [I36V21B_MucBon],'
				SET @SQL = @SQL + ' [I37V21C_MucBon],'
				SET @SQL = @SQL + ' [I38TK21_MucBon],'
				SET @SQL = @SQL + ' [I109NoteBCN],'
				SET @SQL = @SQL + ' [I110NoteSPLBH],'
				SET @SQL = @SQL + ' [I111NoteMeCondBH],'
				SET @SQL = @SQL + ' [I112NoteMeCondNCS],'
				SET @SQL = @SQL + ' [Status],'
				SET @SQL = @SQL + ' [InputUser],'
				SET @SQL = @SQL + ' [Hid],'
				SET @SQL = @SQL + ' [CreatedDate]'
				SET @SQL = @SQL + ' FROM PageIndex'
				SET @SQL = @SQL + ' WHERE RowIndex > ' + convert(nvarchar, @PageLowerBound)
				IF @PageSize > 0
				BEGIN
					SET @SQL = @SQL + ' AND RowIndex <= ' + convert(nvarchar, @PageUpperBound)
				END
				SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				exec sp_executesql @SQL
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) as TotalRowCount'
				SET @SQL = @SQL + ' FROM [dbo].[GPP]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				exec sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.GPP_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.GPP_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.GPP_Insert
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: KVT (kvt.dyndns.org)
-- Purpose: Inserts a record into the GPP table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.GPP_Insert
(

	@Id bigint    OUTPUT,

	@I1InputDate datetime   ,

	@I2KhiAm float   ,

	@I3Cond float   ,

	@I4pCcp float   ,

	@I6Pi0101 float   ,

	@I7Fiq0401 float   ,

	@I8Fiq0301 float   ,

	@I9Fiq0302 float   ,

	@I10Fi102ByPass float   ,

	@I11Fiq26010h float   ,

	@I12Fiq260124h float   ,

	@I13Fiq2601Da float   ,

	@I14Fiq26020h float   ,

	@I15Fiq260224h float   ,

	@I16Fiq2602Da float   ,

	@I17Fiq26030h float   ,

	@I18Fiq260324h float   ,

	@I19Fiq2603Da float   ,

	@I20XeBon float   ,

	@I21Fiq2402 float   ,

	@I22Me240h float   ,

	@I23Me2424h float   ,

	@I24TenMeCondBh nvarchar (50)  ,

	@I25Me250h float   ,

	@I26Me2524h float   ,

	@I27Me260h float   ,

	@I28Me2624h float   ,

	@I29KctvNhanLpg float   ,

	@I30KctvNhanCond float   ,

	@I31ApSuat float   ,

	@I32Me13a float   ,

	@I33Me13b float   ,

	@I34Fiq5801 float   ,

	@I35v21aMucBon float   ,

	@I36v21bMucBon float   ,

	@I37v21cMucBon float   ,

	@I38Tk21MucBon float   ,

	@I109NoteBcn nvarchar (500)  ,

	@I110NoteSplbh nvarchar (500)  ,

	@I111NoteMeCondBh nvarchar (500)  ,

	@I112NoteMeCondNcs nvarchar (500)  ,

	@Status int   ,

	@InputUser int   ,

	@Hid bigint   ,

	@CreatedDate datetime   
)
AS


					
				INSERT INTO [dbo].[GPP]
					(
					[I1InputDate]
					,[I2KhiAm]
					,[I3Cond]
					,[I4P_CCP]
					,[I6PI0101]
					,[I7FIQ0401]
					,[I8FIQ0301]
					,[I9FIQ0302]
					,[I10FI102ByPass]
					,[I11FIQ2601_0h]
					,[I12FIQ2601_24h]
					,[I13FIQ2601_DA]
					,[I14FIQ2602_0h]
					,[I15FIQ2602_24h]
					,[I16FIQ2602_DA]
					,[I17FIQ2603_0h]
					,[I18FIQ2603_24h]
					,[I19FIQ2603_DA]
					,[I20XeBon]
					,[I21FIQ2402]
					,[I22ME24_0h]
					,[I23ME24_24h]
					,[I24TenMeCondBH]
					,[I25ME25_0h]
					,[I26ME25_24h]
					,[I27ME26_0h]
					,[I28ME26_24h]
					,[I29KCTV_nhan_LPG]
					,[I30KCTV_nhan_Cond]
					,[I31ApSuat]
					,[I32ME13A]
					,[I33ME13B]
					,[I34FIQ5801]
					,[I35V21A_MucBon]
					,[I36V21B_MucBon]
					,[I37V21C_MucBon]
					,[I38TK21_MucBon]
					,[I109NoteBCN]
					,[I110NoteSPLBH]
					,[I111NoteMeCondBH]
					,[I112NoteMeCondNCS]
					,[Status]
					,[InputUser]
					,[Hid]
					,[CreatedDate]
					)
				VALUES
					(
					@I1InputDate
					,@I2KhiAm
					,@I3Cond
					,@I4pCcp
					,@I6Pi0101
					,@I7Fiq0401
					,@I8Fiq0301
					,@I9Fiq0302
					,@I10Fi102ByPass
					,@I11Fiq26010h
					,@I12Fiq260124h
					,@I13Fiq2601Da
					,@I14Fiq26020h
					,@I15Fiq260224h
					,@I16Fiq2602Da
					,@I17Fiq26030h
					,@I18Fiq260324h
					,@I19Fiq2603Da
					,@I20XeBon
					,@I21Fiq2402
					,@I22Me240h
					,@I23Me2424h
					,@I24TenMeCondBh
					,@I25Me250h
					,@I26Me2524h
					,@I27Me260h
					,@I28Me2624h
					,@I29KctvNhanLpg
					,@I30KctvNhanCond
					,@I31ApSuat
					,@I32Me13a
					,@I33Me13b
					,@I34Fiq5801
					,@I35v21aMucBon
					,@I36v21bMucBon
					,@I37v21cMucBon
					,@I38Tk21MucBon
					,@I109NoteBcn
					,@I110NoteSplbh
					,@I111NoteMeCondBh
					,@I112NoteMeCondNcs
					,@Status
					,@InputUser
					,@Hid
					,@CreatedDate
					)
				
				-- Get the identity value
				SET @Id = SCOPE_IDENTITY()
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.GPP_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.GPP_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.GPP_Update
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: KVT (kvt.dyndns.org)
-- Purpose: Updates a record in the GPP table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.GPP_Update
(

	@Id bigint   ,

	@I1InputDate datetime   ,

	@I2KhiAm float   ,

	@I3Cond float   ,

	@I4pCcp float   ,

	@I6Pi0101 float   ,

	@I7Fiq0401 float   ,

	@I8Fiq0301 float   ,

	@I9Fiq0302 float   ,

	@I10Fi102ByPass float   ,

	@I11Fiq26010h float   ,

	@I12Fiq260124h float   ,

	@I13Fiq2601Da float   ,

	@I14Fiq26020h float   ,

	@I15Fiq260224h float   ,

	@I16Fiq2602Da float   ,

	@I17Fiq26030h float   ,

	@I18Fiq260324h float   ,

	@I19Fiq2603Da float   ,

	@I20XeBon float   ,

	@I21Fiq2402 float   ,

	@I22Me240h float   ,

	@I23Me2424h float   ,

	@I24TenMeCondBh nvarchar (50)  ,

	@I25Me250h float   ,

	@I26Me2524h float   ,

	@I27Me260h float   ,

	@I28Me2624h float   ,

	@I29KctvNhanLpg float   ,

	@I30KctvNhanCond float   ,

	@I31ApSuat float   ,

	@I32Me13a float   ,

	@I33Me13b float   ,

	@I34Fiq5801 float   ,

	@I35v21aMucBon float   ,

	@I36v21bMucBon float   ,

	@I37v21cMucBon float   ,

	@I38Tk21MucBon float   ,

	@I109NoteBcn nvarchar (500)  ,

	@I110NoteSplbh nvarchar (500)  ,

	@I111NoteMeCondBh nvarchar (500)  ,

	@I112NoteMeCondNcs nvarchar (500)  ,

	@Status int   ,

	@InputUser int   ,

	@Hid bigint   ,

	@CreatedDate datetime   
)
AS


				
				
				-- Modify the updatable columns
				UPDATE
					[dbo].[GPP]
				SET
					[I1InputDate] = @I1InputDate
					,[I2KhiAm] = @I2KhiAm
					,[I3Cond] = @I3Cond
					,[I4P_CCP] = @I4pCcp
					,[I6PI0101] = @I6Pi0101
					,[I7FIQ0401] = @I7Fiq0401
					,[I8FIQ0301] = @I8Fiq0301
					,[I9FIQ0302] = @I9Fiq0302
					,[I10FI102ByPass] = @I10Fi102ByPass
					,[I11FIQ2601_0h] = @I11Fiq26010h
					,[I12FIQ2601_24h] = @I12Fiq260124h
					,[I13FIQ2601_DA] = @I13Fiq2601Da
					,[I14FIQ2602_0h] = @I14Fiq26020h
					,[I15FIQ2602_24h] = @I15Fiq260224h
					,[I16FIQ2602_DA] = @I16Fiq2602Da
					,[I17FIQ2603_0h] = @I17Fiq26030h
					,[I18FIQ2603_24h] = @I18Fiq260324h
					,[I19FIQ2603_DA] = @I19Fiq2603Da
					,[I20XeBon] = @I20XeBon
					,[I21FIQ2402] = @I21Fiq2402
					,[I22ME24_0h] = @I22Me240h
					,[I23ME24_24h] = @I23Me2424h
					,[I24TenMeCondBH] = @I24TenMeCondBh
					,[I25ME25_0h] = @I25Me250h
					,[I26ME25_24h] = @I26Me2524h
					,[I27ME26_0h] = @I27Me260h
					,[I28ME26_24h] = @I28Me2624h
					,[I29KCTV_nhan_LPG] = @I29KctvNhanLpg
					,[I30KCTV_nhan_Cond] = @I30KctvNhanCond
					,[I31ApSuat] = @I31ApSuat
					,[I32ME13A] = @I32Me13a
					,[I33ME13B] = @I33Me13b
					,[I34FIQ5801] = @I34Fiq5801
					,[I35V21A_MucBon] = @I35v21aMucBon
					,[I36V21B_MucBon] = @I36v21bMucBon
					,[I37V21C_MucBon] = @I37v21cMucBon
					,[I38TK21_MucBon] = @I38Tk21MucBon
					,[I109NoteBCN] = @I109NoteBcn
					,[I110NoteSPLBH] = @I110NoteSplbh
					,[I111NoteMeCondBH] = @I111NoteMeCondBh
					,[I112NoteMeCondNCS] = @I112NoteMeCondNcs
					,[Status] = @Status
					,[InputUser] = @InputUser
					,[Hid] = @Hid
					,[CreatedDate] = @CreatedDate
				WHERE
[Id] = @Id 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.GPP_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.GPP_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.GPP_Delete
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: KVT (kvt.dyndns.org)
-- Purpose: Deletes a record in the GPP table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.GPP_Delete
(

	@Id bigint   
)
AS


				DELETE FROM [dbo].[GPP] WITH (ROWLOCK) 
				WHERE
					[Id] = @Id
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.GPP_GetByStatus procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.GPP_GetByStatus') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.GPP_GetByStatus
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: KVT (kvt.dyndns.org)
-- Purpose: Select records from the GPP table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.GPP_GetByStatus
(

	@Status int   
)
AS


				SET ANSI_NULLS OFF
				
				SELECT
					[Id],
					[I1InputDate],
					[I2KhiAm],
					[I3Cond],
					[I4P_CCP],
					[I6PI0101],
					[I7FIQ0401],
					[I8FIQ0301],
					[I9FIQ0302],
					[I10FI102ByPass],
					[I11FIQ2601_0h],
					[I12FIQ2601_24h],
					[I13FIQ2601_DA],
					[I14FIQ2602_0h],
					[I15FIQ2602_24h],
					[I16FIQ2602_DA],
					[I17FIQ2603_0h],
					[I18FIQ2603_24h],
					[I19FIQ2603_DA],
					[I20XeBon],
					[I21FIQ2402],
					[I22ME24_0h],
					[I23ME24_24h],
					[I24TenMeCondBH],
					[I25ME25_0h],
					[I26ME25_24h],
					[I27ME26_0h],
					[I28ME26_24h],
					[I29KCTV_nhan_LPG],
					[I30KCTV_nhan_Cond],
					[I31ApSuat],
					[I32ME13A],
					[I33ME13B],
					[I34FIQ5801],
					[I35V21A_MucBon],
					[I36V21B_MucBon],
					[I37V21C_MucBon],
					[I38TK21_MucBon],
					[I109NoteBCN],
					[I110NoteSPLBH],
					[I111NoteMeCondBH],
					[I112NoteMeCondNCS],
					[Status],
					[InputUser],
					[Hid],
					[CreatedDate]
				FROM
					[dbo].[GPP]
				WHERE
					[Status] = @Status
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.GPP_GetByHid procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.GPP_GetByHid') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.GPP_GetByHid
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: KVT (kvt.dyndns.org)
-- Purpose: Select records from the GPP table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.GPP_GetByHid
(

	@Hid bigint   
)
AS


				SET ANSI_NULLS OFF
				
				SELECT
					[Id],
					[I1InputDate],
					[I2KhiAm],
					[I3Cond],
					[I4P_CCP],
					[I6PI0101],
					[I7FIQ0401],
					[I8FIQ0301],
					[I9FIQ0302],
					[I10FI102ByPass],
					[I11FIQ2601_0h],
					[I12FIQ2601_24h],
					[I13FIQ2601_DA],
					[I14FIQ2602_0h],
					[I15FIQ2602_24h],
					[I16FIQ2602_DA],
					[I17FIQ2603_0h],
					[I18FIQ2603_24h],
					[I19FIQ2603_DA],
					[I20XeBon],
					[I21FIQ2402],
					[I22ME24_0h],
					[I23ME24_24h],
					[I24TenMeCondBH],
					[I25ME25_0h],
					[I26ME25_24h],
					[I27ME26_0h],
					[I28ME26_24h],
					[I29KCTV_nhan_LPG],
					[I30KCTV_nhan_Cond],
					[I31ApSuat],
					[I32ME13A],
					[I33ME13B],
					[I34FIQ5801],
					[I35V21A_MucBon],
					[I36V21B_MucBon],
					[I37V21C_MucBon],
					[I38TK21_MucBon],
					[I109NoteBCN],
					[I110NoteSPLBH],
					[I111NoteMeCondBH],
					[I112NoteMeCondNCS],
					[Status],
					[InputUser],
					[Hid],
					[CreatedDate]
				FROM
					[dbo].[GPP]
				WHERE
					[Hid] = @Hid
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.GPP_GetByInputUser procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.GPP_GetByInputUser') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.GPP_GetByInputUser
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: KVT (kvt.dyndns.org)
-- Purpose: Select records from the GPP table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.GPP_GetByInputUser
(

	@InputUser int   
)
AS


				SET ANSI_NULLS OFF
				
				SELECT
					[Id],
					[I1InputDate],
					[I2KhiAm],
					[I3Cond],
					[I4P_CCP],
					[I6PI0101],
					[I7FIQ0401],
					[I8FIQ0301],
					[I9FIQ0302],
					[I10FI102ByPass],
					[I11FIQ2601_0h],
					[I12FIQ2601_24h],
					[I13FIQ2601_DA],
					[I14FIQ2602_0h],
					[I15FIQ2602_24h],
					[I16FIQ2602_DA],
					[I17FIQ2603_0h],
					[I18FIQ2603_24h],
					[I19FIQ2603_DA],
					[I20XeBon],
					[I21FIQ2402],
					[I22ME24_0h],
					[I23ME24_24h],
					[I24TenMeCondBH],
					[I25ME25_0h],
					[I26ME25_24h],
					[I27ME26_0h],
					[I28ME26_24h],
					[I29KCTV_nhan_LPG],
					[I30KCTV_nhan_Cond],
					[I31ApSuat],
					[I32ME13A],
					[I33ME13B],
					[I34FIQ5801],
					[I35V21A_MucBon],
					[I36V21B_MucBon],
					[I37V21C_MucBon],
					[I38TK21_MucBon],
					[I109NoteBCN],
					[I110NoteSPLBH],
					[I111NoteMeCondBH],
					[I112NoteMeCondNCS],
					[Status],
					[InputUser],
					[Hid],
					[CreatedDate]
				FROM
					[dbo].[GPP]
				WHERE
					[InputUser] = @InputUser
				
				Select @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.GPP_GetById procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.GPP_GetById') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.GPP_GetById
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: KVT (kvt.dyndns.org)
-- Purpose: Select records from the GPP table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.GPP_GetById
(

	@Id bigint   
)
AS


				SELECT
					[Id],
					[I1InputDate],
					[I2KhiAm],
					[I3Cond],
					[I4P_CCP],
					[I6PI0101],
					[I7FIQ0401],
					[I8FIQ0301],
					[I9FIQ0302],
					[I10FI102ByPass],
					[I11FIQ2601_0h],
					[I12FIQ2601_24h],
					[I13FIQ2601_DA],
					[I14FIQ2602_0h],
					[I15FIQ2602_24h],
					[I16FIQ2602_DA],
					[I17FIQ2603_0h],
					[I18FIQ2603_24h],
					[I19FIQ2603_DA],
					[I20XeBon],
					[I21FIQ2402],
					[I22ME24_0h],
					[I23ME24_24h],
					[I24TenMeCondBH],
					[I25ME25_0h],
					[I26ME25_24h],
					[I27ME26_0h],
					[I28ME26_24h],
					[I29KCTV_nhan_LPG],
					[I30KCTV_nhan_Cond],
					[I31ApSuat],
					[I32ME13A],
					[I33ME13B],
					[I34FIQ5801],
					[I35V21A_MucBon],
					[I36V21B_MucBon],
					[I37V21C_MucBon],
					[I38TK21_MucBon],
					[I109NoteBCN],
					[I110NoteSPLBH],
					[I111NoteMeCondBH],
					[I112NoteMeCondNCS],
					[Status],
					[InputUser],
					[Hid],
					[CreatedDate]
				FROM
					[dbo].[GPP]
				WHERE
					[Id] = @Id
			Select @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.GPP_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.GPP_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.GPP_Find
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By: KVT (kvt.dyndns.org)
-- Purpose: Finds records in the GPP table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.GPP_Find
(

	@SearchUsingOR bit   = null ,

	@Id bigint   = null ,

	@I1InputDate datetime   = null ,

	@I2KhiAm float   = null ,

	@I3Cond float   = null ,

	@I4pCcp float   = null ,

	@I6Pi0101 float   = null ,

	@I7Fiq0401 float   = null ,

	@I8Fiq0301 float   = null ,

	@I9Fiq0302 float   = null ,

	@I10Fi102ByPass float   = null ,

	@I11Fiq26010h float   = null ,

	@I12Fiq260124h float   = null ,

	@I13Fiq2601Da float   = null ,

	@I14Fiq26020h float   = null ,

	@I15Fiq260224h float   = null ,

	@I16Fiq2602Da float   = null ,

	@I17Fiq26030h float   = null ,

	@I18Fiq260324h float   = null ,

	@I19Fiq2603Da float   = null ,

	@I20XeBon float   = null ,

	@I21Fiq2402 float   = null ,

	@I22Me240h float   = null ,

	@I23Me2424h float   = null ,

	@I24TenMeCondBh nvarchar (50)  = null ,

	@I25Me250h float   = null ,

	@I26Me2524h float   = null ,

	@I27Me260h float   = null ,

	@I28Me2624h float   = null ,

	@I29KctvNhanLpg float   = null ,

	@I30KctvNhanCond float   = null ,

	@I31ApSuat float   = null ,

	@I32Me13a float   = null ,

	@I33Me13b float   = null ,

	@I34Fiq5801 float   = null ,

	@I35v21aMucBon float   = null ,

	@I36v21bMucBon float   = null ,

	@I37v21cMucBon float   = null ,

	@I38Tk21MucBon float   = null ,

	@I109NoteBcn nvarchar (500)  = null ,

	@I110NoteSplbh nvarchar (500)  = null ,

	@I111NoteMeCondBh nvarchar (500)  = null ,

	@I112NoteMeCondNcs nvarchar (500)  = null ,

	@Status int   = null ,

	@InputUser int   = null ,

	@Hid bigint   = null ,

	@CreatedDate datetime   = null 
)
AS


				
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [Id]
	, [I1InputDate]
	, [I2KhiAm]
	, [I3Cond]
	, [I4P_CCP]
	, [I6PI0101]
	, [I7FIQ0401]
	, [I8FIQ0301]
	, [I9FIQ0302]
	, [I10FI102ByPass]
	, [I11FIQ2601_0h]
	, [I12FIQ2601_24h]
	, [I13FIQ2601_DA]
	, [I14FIQ2602_0h]
	, [I15FIQ2602_24h]
	, [I16FIQ2602_DA]
	, [I17FIQ2603_0h]
	, [I18FIQ2603_24h]
	, [I19FIQ2603_DA]
	, [I20XeBon]
	, [I21FIQ2402]
	, [I22ME24_0h]
	, [I23ME24_24h]
	, [I24TenMeCondBH]
	, [I25ME25_0h]
	, [I26ME25_24h]
	, [I27ME26_0h]
	, [I28ME26_24h]
	, [I29KCTV_nhan_LPG]
	, [I30KCTV_nhan_Cond]
	, [I31ApSuat]
	, [I32ME13A]
	, [I33ME13B]
	, [I34FIQ5801]
	, [I35V21A_MucBon]
	, [I36V21B_MucBon]
	, [I37V21C_MucBon]
	, [I38TK21_MucBon]
	, [I109NoteBCN]
	, [I110NoteSPLBH]
	, [I111NoteMeCondBH]
	, [I112NoteMeCondNCS]
	, [Status]
	, [InputUser]
	, [Hid]
	, [CreatedDate]
    FROM
	[dbo].[GPP]
    WHERE 
	 ([Id] = @Id OR @Id is null)
	AND ([I1InputDate] = @I1InputDate OR @I1InputDate is null)
	AND ([I2KhiAm] = @I2KhiAm OR @I2KhiAm is null)
	AND ([I3Cond] = @I3Cond OR @I3Cond is null)
	AND ([I4P_CCP] = @I4pCcp OR @I4pCcp is null)
	AND ([I6PI0101] = @I6Pi0101 OR @I6Pi0101 is null)
	AND ([I7FIQ0401] = @I7Fiq0401 OR @I7Fiq0401 is null)
	AND ([I8FIQ0301] = @I8Fiq0301 OR @I8Fiq0301 is null)
	AND ([I9FIQ0302] = @I9Fiq0302 OR @I9Fiq0302 is null)
	AND ([I10FI102ByPass] = @I10Fi102ByPass OR @I10Fi102ByPass is null)
	AND ([I11FIQ2601_0h] = @I11Fiq26010h OR @I11Fiq26010h is null)
	AND ([I12FIQ2601_24h] = @I12Fiq260124h OR @I12Fiq260124h is null)
	AND ([I13FIQ2601_DA] = @I13Fiq2601Da OR @I13Fiq2601Da is null)
	AND ([I14FIQ2602_0h] = @I14Fiq26020h OR @I14Fiq26020h is null)
	AND ([I15FIQ2602_24h] = @I15Fiq260224h OR @I15Fiq260224h is null)
	AND ([I16FIQ2602_DA] = @I16Fiq2602Da OR @I16Fiq2602Da is null)
	AND ([I17FIQ2603_0h] = @I17Fiq26030h OR @I17Fiq26030h is null)
	AND ([I18FIQ2603_24h] = @I18Fiq260324h OR @I18Fiq260324h is null)
	AND ([I19FIQ2603_DA] = @I19Fiq2603Da OR @I19Fiq2603Da is null)
	AND ([I20XeBon] = @I20XeBon OR @I20XeBon is null)
	AND ([I21FIQ2402] = @I21Fiq2402 OR @I21Fiq2402 is null)
	AND ([I22ME24_0h] = @I22Me240h OR @I22Me240h is null)
	AND ([I23ME24_24h] = @I23Me2424h OR @I23Me2424h is null)
	AND ([I24TenMeCondBH] = @I24TenMeCondBh OR @I24TenMeCondBh is null)
	AND ([I25ME25_0h] = @I25Me250h OR @I25Me250h is null)
	AND ([I26ME25_24h] = @I26Me2524h OR @I26Me2524h is null)
	AND ([I27ME26_0h] = @I27Me260h OR @I27Me260h is null)
	AND ([I28ME26_24h] = @I28Me2624h OR @I28Me2624h is null)
	AND ([I29KCTV_nhan_LPG] = @I29KctvNhanLpg OR @I29KctvNhanLpg is null)
	AND ([I30KCTV_nhan_Cond] = @I30KctvNhanCond OR @I30KctvNhanCond is null)
	AND ([I31ApSuat] = @I31ApSuat OR @I31ApSuat is null)
	AND ([I32ME13A] = @I32Me13a OR @I32Me13a is null)
	AND ([I33ME13B] = @I33Me13b OR @I33Me13b is null)
	AND ([I34FIQ5801] = @I34Fiq5801 OR @I34Fiq5801 is null)
	AND ([I35V21A_MucBon] = @I35v21aMucBon OR @I35v21aMucBon is null)
	AND ([I36V21B_MucBon] = @I36v21bMucBon OR @I36v21bMucBon is null)
	AND ([I37V21C_MucBon] = @I37v21cMucBon OR @I37v21cMucBon is null)
	AND ([I38TK21_MucBon] = @I38Tk21MucBon OR @I38Tk21MucBon is null)
	AND ([I109NoteBCN] = @I109NoteBcn OR @I109NoteBcn is null)
	AND ([I110NoteSPLBH] = @I110NoteSplbh OR @I110NoteSplbh is null)
	AND ([I111NoteMeCondBH] = @I111NoteMeCondBh OR @I111NoteMeCondBh is null)
	AND ([I112NoteMeCondNCS] = @I112NoteMeCondNcs OR @I112NoteMeCondNcs is null)
	AND ([Status] = @Status OR @Status is null)
	AND ([InputUser] = @InputUser OR @InputUser is null)
	AND ([Hid] = @Hid OR @Hid is null)
	AND ([CreatedDate] = @CreatedDate OR @CreatedDate is null)
						
  END
  ELSE
  BEGIN
    SELECT
	  [Id]
	, [I1InputDate]
	, [I2KhiAm]
	, [I3Cond]
	, [I4P_CCP]
	, [I6PI0101]
	, [I7FIQ0401]
	, [I8FIQ0301]
	, [I9FIQ0302]
	, [I10FI102ByPass]
	, [I11FIQ2601_0h]
	, [I12FIQ2601_24h]
	, [I13FIQ2601_DA]
	, [I14FIQ2602_0h]
	, [I15FIQ2602_24h]
	, [I16FIQ2602_DA]
	, [I17FIQ2603_0h]
	, [I18FIQ2603_24h]
	, [I19FIQ2603_DA]
	, [I20XeBon]
	, [I21FIQ2402]
	, [I22ME24_0h]
	, [I23ME24_24h]
	, [I24TenMeCondBH]
	, [I25ME25_0h]
	, [I26ME25_24h]
	, [I27ME26_0h]
	, [I28ME26_24h]
	, [I29KCTV_nhan_LPG]
	, [I30KCTV_nhan_Cond]
	, [I31ApSuat]
	, [I32ME13A]
	, [I33ME13B]
	, [I34FIQ5801]
	, [I35V21A_MucBon]
	, [I36V21B_MucBon]
	, [I37V21C_MucBon]
	, [I38TK21_MucBon]
	, [I109NoteBCN]
	, [I110NoteSPLBH]
	, [I111NoteMeCondBH]
	, [I112NoteMeCondNCS]
	, [Status]
	, [InputUser]
	, [Hid]
	, [CreatedDate]
    FROM
	[dbo].[GPP]
    WHERE 
	 ([Id] = @Id AND @Id is not null)
	OR ([I1InputDate] = @I1InputDate AND @I1InputDate is not null)
	OR ([I2KhiAm] = @I2KhiAm AND @I2KhiAm is not null)
	OR ([I3Cond] = @I3Cond AND @I3Cond is not null)
	OR ([I4P_CCP] = @I4pCcp AND @I4pCcp is not null)
	OR ([I6PI0101] = @I6Pi0101 AND @I6Pi0101 is not null)
	OR ([I7FIQ0401] = @I7Fiq0401 AND @I7Fiq0401 is not null)
	OR ([I8FIQ0301] = @I8Fiq0301 AND @I8Fiq0301 is not null)
	OR ([I9FIQ0302] = @I9Fiq0302 AND @I9Fiq0302 is not null)
	OR ([I10FI102ByPass] = @I10Fi102ByPass AND @I10Fi102ByPass is not null)
	OR ([I11FIQ2601_0h] = @I11Fiq26010h AND @I11Fiq26010h is not null)
	OR ([I12FIQ2601_24h] = @I12Fiq260124h AND @I12Fiq260124h is not null)
	OR ([I13FIQ2601_DA] = @I13Fiq2601Da AND @I13Fiq2601Da is not null)
	OR ([I14FIQ2602_0h] = @I14Fiq26020h AND @I14Fiq26020h is not null)
	OR ([I15FIQ2602_24h] = @I15Fiq260224h AND @I15Fiq260224h is not null)
	OR ([I16FIQ2602_DA] = @I16Fiq2602Da AND @I16Fiq2602Da is not null)
	OR ([I17FIQ2603_0h] = @I17Fiq26030h AND @I17Fiq26030h is not null)
	OR ([I18FIQ2603_24h] = @I18Fiq260324h AND @I18Fiq260324h is not null)
	OR ([I19FIQ2603_DA] = @I19Fiq2603Da AND @I19Fiq2603Da is not null)
	OR ([I20XeBon] = @I20XeBon AND @I20XeBon is not null)
	OR ([I21FIQ2402] = @I21Fiq2402 AND @I21Fiq2402 is not null)
	OR ([I22ME24_0h] = @I22Me240h AND @I22Me240h is not null)
	OR ([I23ME24_24h] = @I23Me2424h AND @I23Me2424h is not null)
	OR ([I24TenMeCondBH] = @I24TenMeCondBh AND @I24TenMeCondBh is not null)
	OR ([I25ME25_0h] = @I25Me250h AND @I25Me250h is not null)
	OR ([I26ME25_24h] = @I26Me2524h AND @I26Me2524h is not null)
	OR ([I27ME26_0h] = @I27Me260h AND @I27Me260h is not null)
	OR ([I28ME26_24h] = @I28Me2624h AND @I28Me2624h is not null)
	OR ([I29KCTV_nhan_LPG] = @I29KctvNhanLpg AND @I29KctvNhanLpg is not null)
	OR ([I30KCTV_nhan_Cond] = @I30KctvNhanCond AND @I30KctvNhanCond is not null)
	OR ([I31ApSuat] = @I31ApSuat AND @I31ApSuat is not null)
	OR ([I32ME13A] = @I32Me13a AND @I32Me13a is not null)
	OR ([I33ME13B] = @I33Me13b AND @I33Me13b is not null)
	OR ([I34FIQ5801] = @I34Fiq5801 AND @I34Fiq5801 is not null)
	OR ([I35V21A_MucBon] = @I35v21aMucBon AND @I35v21aMucBon is not null)
	OR ([I36V21B_MucBon] = @I36v21bMucBon AND @I36v21bMucBon is not null)
	OR ([I37V21C_MucBon] = @I37v21cMucBon AND @I37v21cMucBon is not null)
	OR ([I38TK21_MucBon] = @I38Tk21MucBon AND @I38Tk21MucBon is not null)
	OR ([I109NoteBCN] = @I109NoteBcn AND @I109NoteBcn is not null)
	OR ([I110NoteSPLBH] = @I110NoteSplbh AND @I110NoteSplbh is not null)
	OR ([I111NoteMeCondBH] = @I111NoteMeCondBh AND @I111NoteMeCondBh is not null)
	OR ([I112NoteMeCondNCS] = @I112NoteMeCondNcs AND @I112NoteMeCondNcs is not null)
	OR ([Status] = @Status AND @Status is not null)
	OR ([InputUser] = @InputUser AND @InputUser is not null)
	OR ([Hid] = @Hid AND @Hid is not null)
	OR ([CreatedDate] = @CreatedDate AND @CreatedDate is not null)
	Select @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

